2

We have a complex older system and we want to possibly transition to using Require.js
One question I have is whether it is possible to set up specific versions of a file.
I'm not talking about "multiple versions" in the same page.
What I'm thinking is this:

  • Module1
  • Module2
    • Module1
  • Module3
    • Module1
  • Module4
    • Module2
    • Module3

I want a way to version Module1 so that I can go and change the version number in a single place.
I know I can use: require.config({ urlArgs: "bust=v3" }) but can I do that in the top of the file for Module1 and have it only refer to that Module?

2
  • Are you talking about cache busting, or is there some other reason you want to have a version number?
    – cspotcode
    Mar 8, 2013 at 14:40
  • I am talking about cache busting, but I want to only "bust the cache" of specific files. We don't want to update 1 file in our system and have the users redownload another 100 JS files that didn't change. Mar 8, 2013 at 14:54

1 Answer 1

0

Try setting the paths object in your RequireJS configuration. This will map a module's name to the URL RequireJS should download.

http://requirejs.org/docs/api.html#config-paths

paths: {
    'Module1': 'path/to/Module1_v1'
}
4
  • But that would require changing the actual filename during versioning right? Which would cause problems with source control history. Or could I possibly do: 'Module1': 'path/to/Module1?bust=v2'? Mar 8, 2013 at 14:55
  • I'm not sure if you can add URL query arguments to a path because RequireJS needs to add the ".js" suffix to the URL. At least if you're using Git, renaming files won't break your source control history.
    – cspotcode
    Mar 8, 2013 at 15:12
  • Sadly, not using Git. Using Visual Source Safe (really) Mar 8, 2013 at 15:15
  • You could use a sym-link and rename that every time you need to bump the version.
    – Ben
    Mar 11, 2013 at 2:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.