Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

version tag for modules for browser caching #55

Closed
ryanflorence opened this issue Dec 12, 2011 · 3 comments
Closed

version tag for modules for browser caching #55

ryanflorence opened this issue Dec 12, 2011 · 3 comments

Comments

@ryanflorence
Copy link

Consider this build config:

({
  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, but we don't have control over the tags that RequireJS injects aside from urlArgs.

Currently we set urlArgs to the build number 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 to be downloaded again.

@jrburke
Copy link
Member

jrburke commented Dec 12, 2011

The suggested way to do this with the existing capabilities would be to not use a querystring for the version, but place it as part of the path, so v1/foo.js instead of foo.js?v=1.

Then you can just use the regular paths config in the browser to set the path for 'foo' to the right place:

    requirejs.config({
        paths: {
            foo: 'v1/foo'
        }
    });

Or, if you like the v1 after:

    requirejs.config({
        paths: {
            //loads foo/v1.js
            foo: 'foo/v1'
        }
    });

Using path args instead of querystring args also allows more caching by intermediate proxy servers. At least in the past, some might not cache has heavily for querystring args.

Will that solve the problem?

@ryanflorence
Copy link
Author

Good point. Thanks James.

@millermedeiros
Copy link
Member

someone should build a tool to automate the process.. I was planning to read the build.config file, rename the optimized modules (append SHA/MD5) and generate a version.js file which could be loaded as a separate script or concatenated into the HTML itself to avoid caching it.

related thread on groups

PS: I won't have time to do it anytime soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants