I'm using RequireJS on our site and before the files are deployed to production we are using rjs to minify the files. Currently I am creating several minified files, not a single file.
For better load times on our site we are also using multiple CDNs so the browser will open more download streams and the static content will load as fast as possible.
Here lies my problem. I can configure RequireJS through the baseUrl
parameter to load my scripts from our CDN, but is there a way to configure RequireJS to use a random baseUrl? I know by default this isn't possible, but I was hoping maybe someone here can help me by suggesting a plugin or a method that will do the trick.
The only solution I found was to define the path manually to each file, giving them different CDNs on each definition, but I really hope that there's a better way to do it. An automatic way and not a manual one.
If there's anything I can add, show or answer please let me know.
Thanks in advance.
I don't think the official API supports what you want, but here are some ideas for workaround:
Option 1: embed expressions into the paths config section that randomizes which CDN is used. Below is an example for jQuery but you could repeat something similar for different libraries:
Option 2: Override RequireJS's load method as described in Fine-grained URL control:
Option 3: Write your own Loader Plugin. The below sample code is not a complete solution but it shows the idea of what I mean: