how to use version numbers for js/css modules with curl

13 views
Skip to first unread message

kguelzau

unread,
Apr 5, 2013, 5:39:29 AM4/5/13
to cuj...@googlegroups.com
Hi *,

I just started using curl.js and amd.js and have some problems to transfer our legacy js files to amd.

Today every ressource (js/css/img/...) has a version encoded in the filename (we are not in control of the response headers):
ui/tooltip_5_3_8_0.js and ui/tooltip_5_3_8_0.css

In tooltip.js I require tooltip.css and would like to refer to tooltip.css without the version number:

define(["css!ui/tooltip"], function () { /* code */ });

Is there a "standard" way to automatically insert the version number?

Any pointers?

Kai



kguelzau

unread,
Apr 5, 2013, 11:17:34 AM4/5/13
to
I had a look at the other plugins.
So now I have done this as a plugin:

(function(global){
 
var
    version
= "#VERSION#".split(" ")[0], // #VERSION# is replaced by the buildscript (eg. "8.0.8.0 build 224.1939")
    getSuffix
= function(resourceId, config) {
     
var v;
     
if (!resourceId) {
       
return resourceId;
     
}
      v
= config.suffix || version;
      v
= !v || v.charAt(0) === "#" ? "" : "_" + v;
     
return resourceId.replace(/(\/?[^/\.]*)(\.[^\.]+)?$/, "$1" + v + "$2");
   
};
  define
("curl/plugin/v", {
   
'load': function (resourceId, require, callback, config) {
     
require([getSuffix(resourceId, config)], function(r) {
       
return callback(r);
     
});
   
},
   
'normalize': function (resourceId, toAbsId) {
     
return resourceId;
   
}
 
});
}(this));

define changes to:
define(["v!css!ui/tooltip"], function () { /* code */ });

Kai

unscriptable

unread,
Apr 8, 2013, 7:59:05 PM4/8/13
to cuj...@googlegroups.com
Hello Kai,

That's an interesting way to solve it.  I like that you can inject the version number via config or via build tool.

It's too bad the version number is encoded into the file name, rather than the path somewhere.  If it were in the path, you could use paths:{} or packages:{} mappings to change the ids instead of a plugin.

Regards,

-- John
define(["v!css!ui/tooltip"], function () { /* code */ });

Kai

Reply all
Reply to author
Forward
0 new messages