Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to add a request parameter to dojo module requests via dojo's AMD loader

Tags:

dojo

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.

like image 625
Shilpam Avatar asked Apr 19 '13 17:04

Shilpam


People also ask

What is AMD in dojo?

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.

What is Dojo loader?

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.

How do you define an AMD module?

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.


1 Answers

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.

like image 133
Paul Grime Avatar answered Oct 01 '22 11:10

Paul Grime