I run the optimizer like this
sudo /usr/local/bin/node /tmp/r.j/r.js -o name=main out=test.js baseUrl=.
for test
Now, how do I tell the optimizer to output the filename as a hash of the content (obviously to set max expires) and then rename the dependency in the relevant require calls?
An example situation will be something like this
require({
baseUrl: '{{ STATIC_URL }}js',
paths: {
jquery: 'https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min',
jqueryui: 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min'
}
}, ['order!jquery','order!jqueryui','order!main']);
requirejs should be pulling something like 13KUJAW78M.js
Based on Miller Medeiros’s suggestion I am planning to put all the require calls into a single master file. This will also mean that all such calls will also need to be optimized.
e.g
switch(document.location.pathName){
case '/foo':
require(['sections/foo/main']);
break;
case '/foo/bar':
require(['sections/foo/main', 'core/bar']);
break;
default:
require('sections/home');
}
require(['sections/foo/main']);
should be optimized to a hash file.
Can someone help?
RequireJS optimizer doesn't have this option, but you could rename the files and use the paths config to set alias to the renamed files, see this thread for more info.
On your example for instance, if you rename the files to: 'sections/foo/main.123QWERT.js', 'sections/home.4567ASDFG.js', 'core/bar.0284ZXCV.js' you could just add a paths config like this:
require.config({
paths : {
//alias to new files without JS extension
'core/bar': 'core/bar.0284ZXCV',
'sections/home' : 'sections/home.4567ASDFG',
'sections/foo/main' : 'sections/foo/main.123QWERT'
}
});
The paths config should be on a file that won't be cached, maybe just keep the config on the HTML.
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