Is it possible to modify request urls used by the dojo AMD loader before a request is sent to the server for an AMD module? I would like to append a request parameter with a version number.
The problem we are trying to solve is that we want our javascript files to be cached by the browser unless the application's version is updated. I think we should be able to do that if we can add a version number to the requested URL.
Dojo and Asynchronous Module Definition(AMD) The ArcGIS API for JavaScript is built using Dojo, which fully supports creating classes and modules using Asynchronous Module Definition (AMD) style code.
Dojo was among the first JavaScript libraries to define a module API and publish a loader and build application to solve all of these problems. The original API included the functions dojo. require (request a module), dojo. provide (define a module), and other supporting functions.
Asynchronous module definition (AMD) is a specification for the programming language JavaScript. It defines an application programming interface (API) that defines code modules and their dependencies, and loads them asynchronously if desired.
The paths
config property seems to work for individual modules, and cacheBust
can be used for all modules. Example jsfiddle.
<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>
Giving:
"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"
The hiccup for the paths
approach is the trailing ".js", but for the purposes of versioning I don't think that's an issue as the URL is still unique in the way you want it to be.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With