Is it possible to add a query parameter to dojo module requests via dojo AMD loader

Is it possible to change the request URLs used by the AMD dojo loader before sending the request to the server for the AMD module? I would like to add a query parameter with version number.

The problem we are trying to solve is that we want our javascript files to be cached by the browser if the version of the application is updated. I think we can do this if we can add the version number to the requested URL.

+5
source share
1 answer

The configuration property pathsseems to work for individual modules, but cacheBustcan be used for all modules. Jsfiddle example .

<script>
var dojoConfig = {
    paths: {
        // version a single file by using path with version number
        "aa": "mylib-aa.js?v=1.0",
        // standard path, no explicit versioning
        "bb": "mylib-bb"
    },
    // use v=1.0 for ALL loaded modules
    cacheBust: "v=1.0",
    waitSeconds: 10
};
</script>
<script src="https://ajax.googleapis.com/ajax/libs/dojo/1.8.3/dojo/dojo.js"></script>
<script>
require(["aa", "bb"], function () {});
</script>

Donation:

"NetworkError: 404 Not Found - https://ajax.googleapis.com/ajax/libs/dojo/1.8.3/dojo/mylib-aa.js?v=1.0.js&v=1.0"
"NetworkError: 404 Not Found - https://ajax.googleapis.com/ajax/libs/dojo/1.8.3/dojo/mylib-bb.js?v=1.0"

paths - ".js", , URL- - , .

+10

All Articles