Using CDN with RequireJS Optimizer

RequireJS allows you to load libraries from CDN. In case the CDN does not work, you can also have the backup option where the file can be located somewhere else (in this case, we assume that it is locally local). All this is done in the paths object. For example, to load jQuery from a CDN, and then locally, if the CDN does not work, do the following:

paths : { jquery : [ 'https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min', 'lib/jquery', ]} 

In the above example, first try to find the query from the CDN, and then from lib / jquery.

Question I get the impression that when using the requirejs optimizer, everything becomes miniature and gets confused in one large file. How will the backup option work in the optimizer? Will it be included in the mini file? If so, then there is no advantage to using CDN. But if the backup option is not included in the optimized version, how will the optimized code handle if the CDN goes down?

Thanks in advance for your answers.

+8
requirejs
source share
1 answer

You may have different configuration settings for your regular site compared to what you use to feed the optimizer, so in this case you should use the "empty" configuration in your version of the optimizer so that it does not include jQuery in the combined / shortened version:

 paths: { jquery: "empty:" } 

See the documentation for more information: http://requirejs.org/docs/optimization.html#empty

+3
source share

All Articles