jrburke/r.js — Issue #55: version tag for modules for browser caching
Author: rpflorence
Created: 2011-12-12 18:19:34+00:00
State: open

Consider this build config:

```javascript
({
appDir: "../app",
baseUrl: "./js",
dir: "../public",
modules: [
{ name: "common"},
{ name: "bundles/index", exclude: ["common"]},
{ name: "bundles/gradebook", exclude: ["common"]},
{ name: "bundles/quiz", exclude: ["common"]}
]
})
```

When you land on the index page, the common bundle script tag will be injected by RequireJS. We use the `src=foo.js?v=1` method to take advantage of browser caching, and to not get bitten by it.

Currently we set the `urlArgs` of our require config to the build of our app to ensure users get the latest JS. The problem is that we release every 2 weeks, and have plenty of hot fixes in-between, so our users will have to download every optimized module every time we release :(

I'd propose a "version" key in a module's build config so that when RequireJS fetches a script, it'll append the version as urlArgs (or any other implementation that has the same effect)

({
appDir: "../app",
baseUrl: "./js",
dir: "../public",
modules: [
{ name: "common", version: "1"},
{ name: "bundles/index", exclude: ["common"], version: "2"},
{ name: "bundles/gradebook", exclude: ["common"], version: "2"},
{ name: "bundles/quiz", exclude: ["common"]}
]
})

This way a single module can change versions w/o requiring the entire front-end app from being downloaded again.