RequireJS allows one to load libraries from a CDN. In case the CDN is down, one can also have a backup option where the file can be located some where else (in this case, we assume it is located locally). This is all done in the paths object. For example, in order to load JQuery from a CDN and then locally if the CDN is down, do this:
paths : {
jquery : [
'https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min',
'lib/jquery',
]}
The above example would first try find query from the CDN, then from lib/jquery.
Question I am under the impression that when using the requirejs optimiser, things get minified and obfuscated into one large file. How would the a backup option work in the optimiser? Would it be included in the minified file? If so, then there is absolutely no advantage to using a CDN. But if the backup option is not included in the optimised version, then how will optimised code cope if the CDN goes down?
Thanks in advance for the answers.
You can have different configuration settings for your regular site vs. what you use to feed the optimizer, so in this case you would use an "empty" config in your optimizer version so that it doesn't include jQuery in the combined/minified version:
paths: {
jquery: "empty:"
}
See the documentation for further details: http://requirejs.org/docs/optimization.html#empty
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