javascript - Amazon S3 上的 RequireJS 使用了错误的 URL

标签 javascript amazon-s3 requirejs

我有一个这样的脚本标签:

<script src="https://ZZZ.s3.amazonaws.com/js/require-jquery.js?Signature=XXX&amp;Expires=1369597850&amp;AWSAccessKeyId=YYY" data-main="https://ZZZ.s3.amazonaws.com/js/snippet_create.js?Signature=XXX&amp;Expires=1369597850&amp;AWSAccessKeyId=YYY"></script>

但是 Assets 加载失败,看起来它正在用我的本地页面覆盖资源路径:

Failed to load resource: the server responded with a status of 404 (NOT FOUND) http://localhost:8000/snippet_create.js?Signature=XXX&Expires=1369597850&AWSAccessKeyId=YYY

这一切都在 django-require 中,但它发生在客户端,所以我不确定我知道为什么。

我的构建文件看起来像这样(漂亮的样板):

/**
 * Build profile for django-require.
 * 
 * This supports all the normal configuration available to a r.js build profile. The only gotchas are:
 *
 *   - 'baseUrl' will be overidden by django-require during the build process.
 *   - 'appDir' will be overidden by django-require during the build process.
 *   - 'dir' will be overidden by django-require during the build process. 
 */
({

    baseUrl: 'https://ZZZ.s3.amazonaws.com/js'
    /*
     * paths to use for modules
     */
    paths: {
        "util"      : "util",
        "jquery"    : "require-jquery",
        "ace"       : "ace",
        "bootstrap" : "bootstrap.min"
    },

    /**
     * shim in modules that do not follow amd specs
     */
    shim: {
        "bootstrap": {
          deps: ["jquery"],
          exports: "$.fn.popover"
    }
    /*
     * List the modules that will be optimized. All their immediate and deep
     * dependencies will be included in the module's file when the build is
     * done. A minimum module entry is {name: "module_name"}.
     */
    modules:  [{
            name: "snippet_create",
            exclude: ["jquery"]
    }],

    /*
     * Allow CSS optimizations. Allowed values:
     * - "standard": @import inlining, comment removal and line returns.
     * Removing line returns may have problems in IE, depending on the type
     * of CSS.
     * - "standard.keepLines": Like "standard" but keeps line returns.
     * - "none": Skip CSS optimizations.
     * - "standard.keepComments": Keeps the file comments, but removes line returns.
     * - "standard.keepComments.keepLines": Keeps the file comments and line returns.
     */
    optimizeCss: "standard",

    /*
     * How to optimize all the JS files in the build output directory.
     * Right now only the following values are supported:
     * - "uglify": Uses UglifyJS to minify the code.
     * - "uglify2": Uses UglifyJS2.
     * - "closure": Uses Google's Closure Compiler in simple optimization
     * mode to minify the code. Only available if REQUIRE_ENVIRONMENT is "rhino" (the default).
     * - "none": No minification will be done.
     */
    optimize: "uglify2",

    /*
     * By default, comments that have a license in them are preserved in the
     * output. However, for a larger built files there could be a lot of
     * comment files that may be better served by having a smaller comment
     * at the top of the file that points to the list of all the licenses.
     * This option will turn off the auto-preservation, but you will need
     * work out how best to surface the license information.
     */
    preserveLicenseComments: true,

    /*
     * The default behaviour is to optimize the build layers (the "modules"
     * section of the config) and any other JS file in the directory. However, if
     * the non-build layer JS files will not be loaded after a build, you can
     * skip the optimization of those files, to speed up builds. Set this value
     * to true if you want to skip optimizing those other non-build layer JS
     * files.
     */
    skipDirOptimize: false



})

我不明白为什么 requirejs 使用错误的 url,当它被显式地提供给不同的 url 时。

帮忙吗?

最佳答案

baseUrl 必须是相对的。因为构建需要进程正在尝试访问光盘上的文件并且不会通过 HTTP 下载它们。您可以使用绝对 URL 引用模块,但它们不会包含在输出中。

此外,当使用数据主属性时,您不能使用查询字符串参数。要了解正在发生的事情,请检查 chrome 开发人员工具中的网络面板,您将看到正在请求哪些资源,这将帮助您了解正在发生的事情。

关于javascript - Amazon S3 上的 RequireJS 使用了错误的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16762754/

相关文章:

javascript - Sequelize V5->V6 升级 : Typescript Error Property 'x' does not exist on type 'y'

hadoop - Map Reduce - 如何规划数据文件

django - 如何使用django-storages和Amazon S3将文件从一个路径复制到另一路径?

requirejs - 告诉 RequireJS 不要缩小文件

javascript - 为什么使用 requirejs 定义模块时需要返回?

gulp - RequireJS:丑化不起作用

javascript - Highcharts - Highstock "inputEditDataFormat"中断输入

javascript - DOM 元素何时属于 DOM 树

java - 验证deleteObject是否确实删除了AWS S3 Java sdk中的对象

javascript - 从控制台调用 coffeescript 函数