Optimising requirejs with CDN fallback

July 04, 2014

If you want to utilise a CDN with requireJS you might find some quirks when it comes to the optimiser r.js. As I found at when trying to optimise my modules loading jQuery through a CDN with a local fallback, I received the erorr

[Error: Error: paths fallback not supported in optimizer. Please provide a build config path override for jquery

The issue has been discussed and closed on the r.js issues list. The answer given is to supply a path to jQuery, so that the grunt task knows the path for jQuery. Whilst this does fix the error for r.js it’s not exactly what we have in mind for a fallback, as this will cause the local jQuery fallback file to be included in your optimised requirejs, which kind of defeats of the purpose.

The way around this is pretty simple, instead of supplying a path to your local file which you want excluded you can use the special “empty:” paths config.f

Hi 👋, I'm Anthony Bordonaro. I work as a front-end developer at Envato, where I have the fortune of working with a bunch of fun, encouraging and smart colleagues on the Envato Marketplaces. I'm interested in how technology can help people solve problems and achieve their goals. I like to write about technology, focusing on front-end dev and my journey in learning about managing people and managing teams.

I live in Melbourne, Australia. Home of AFL and my favourite team the Carlton Football Club

You can find me online via Twitter | Github