If you have a project using Dojo (or any comparable framework), you have a few options for how to serve Dojo itself, including:
- Use the Google CDN. This is the most straightforward and a great place to start. You might even hope for caching efficiencies by using such a common CDN, but in practice this does not work out so well. And if you do development from somewhere with a flaky WiFi, every page reload is a spin of the revolver.
- Use Maven to pull in the Dojo WAR. You can then deploy this separately or integrate it via an overlay. Then you discover the joy of waiting for m2e to unpack 8,000 Dojo files over and over again.
There is a another very convenient method that I have never seen suggested but have found to work quite well.
There is a middle ground of serving the pre-packaged Dojo Toolkit yourself, without going through a WAR, and without ever unpacking everything on disk. First, download the ZIP, rename the extension to
.jar, and put it in your
WEB-INF/lib. Then, in Spring, you can map to this JAR via the classpath:
<mvc:resources mapping="/dojo-1.8.0/**" location="classpath:dojo-release-1.8.0/" cache-period="31556926" />
When someone requests from your site, say,
/dojo-1.8.0/dojo/dojo.js, Spring will use the first part of the path to map into your zip-renamed-as-jar, then find the folder and file within the ZIP itself, and serve it directly.