{"action":"created","issue":{"url":"https://api.github.com/repos/jrburke/requirejs/issues/1017","repository_url":"https://api.github.com/repos/jrburke/requirejs","labels_url":"https://api.github.com/repos/jrburke/requirejs/issues/1017/labels{/name}","comments_url":"https://api.github.com/repos/jrburke/requirejs/issues/1017/comments","events_url":"https://api.github.com/repos/jrburke/requirejs/issues/1017/events","html_url":"https://github.com/jrburke/requirejs/pull/1017","id":27109148,"number":1017,"title":"Cache Busting: Inject a configurable string into JS filenames","user":{"login":"jbcpollak","id":188558,"avatar_url":"https://avatars.githubusercontent.com/u/188558?v=3","gravatar_id":"","url":"https://api.github.com/users/jbcpollak","html_url":"https://github.com/jbcpollak","followers_url":"https://api.github.com/users/jbcpollak/followers","following_url":"https://api.github.com/users/jbcpollak/following{/other_user}","gists_url":"https://api.github.com/users/jbcpollak/gists{/gist_id}","starred_url":"https://api.github.com/users/jbcpollak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbcpollak/subscriptions","organizations_url":"https://api.github.com/users/jbcpollak/orgs","repos_url":"https://api.github.com/users/jbcpollak/repos","events_url":"https://api.github.com/users/jbcpollak/events{/privacy}","received_events_url":"https://api.github.com/users/jbcpollak/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2014-02-07T04:41:18Z","updated_at":"2016-02-13T18:09:00Z","closed_at":"2014-02-07T21:57:05Z","pull_request":{"url":"https://api.github.com/repos/jrburke/requirejs/pulls/1017","html_url":"https://github.com/jrburke/requirejs/pull/1017","diff_url":"https://github.com/jrburke/requirejs/pull/1017.diff","patch_url":"https://github.com/jrburke/requirejs/pull/1017.patch"},"body":"A lot of users ask on StackOverflow how to do cache busting with requirejs. The typical answer is to use urlArgs, but that solution has problems. Unfortunately you cannot control all proxy servers that might be between you and your user's web browser. Some of these proxy servers can be unfortunately configured to ignore URL parameters when caching files. If this happens, the wrong version of your JS file will be delivered to your user.\r\n\r\nThis pull request adds a config parameter `cacheSuffix`, which you can use like this:\r\n\r\n    var require = {\r\n        baseUrl: \"/scripts/\",\r\n        cacheSuffix: \".buildNumber\"\r\n    }\r\n\r\nUse your build system or server environment to replace `buildNumber` with a revision id / software version / favorite color.\r\n\r\nUsing require like this:\r\n\r\n    require([\"myModule\"], function() {\r\n        // no-op;\r\n    });\r\n\r\nWill cause require to request this file:\r\n\r\n    http://yourserver.com/scripts/myModule.buildNumber.js\r\n\r\nOn our server environment, we use url rewrite rules to strip out the buildNumber, and serve the correct JS file. This way we don't actually have to worry about renaming all of our JS files.\r\n\r\nThe patch will ignore any script that specifies a protocol, and it will not affect any non-JS files.\r\n\r\nThis works well for us in our environment, but I realize some users would prefer a prefix rather than a suffix, so I would understand if you did not want to incorporate this exact patch into require. I hope you will consider something like this solution however.\r\n\r\nI did consider implementing this using a callback method that could be provided in config, like a 'rewriteUrl()' function, but decided the complexity of a function like that would be too high for the average developer to wrestle with.\r\n\r\nHere are some of the questions on SO for reference:\r\n\r\nhttp://stackoverflow.com/questions/18242756/requirejs-and-proxy-caching/21619297#21619297\r\n\r\nhttp://stackoverflow.com/questions/13833094/require-js-how-can-i-set-a-version-on-required-modules-as-part-of-the-url/21619238#21619238"},"comment":{"url":"https://api.github.com/repos/jrburke/requirejs/issues/comments/183716702","html_url":"https://github.com/jrburke/requirejs/pull/1017#issuecomment-183716702","issue_url":"https://api.github.com/repos/jrburke/requirejs/issues/1017","id":183716702,"user":{"login":"mloayzagahona","id":722671,"avatar_url":"https://avatars.githubusercontent.com/u/722671?v=3","gravatar_id":"","url":"https://api.github.com/users/mloayzagahona","html_url":"https://github.com/mloayzagahona","followers_url":"https://api.github.com/users/mloayzagahona/followers","following_url":"https://api.github.com/users/mloayzagahona/following{/other_user}","gists_url":"https://api.github.com/users/mloayzagahona/gists{/gist_id}","starred_url":"https://api.github.com/users/mloayzagahona/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mloayzagahona/subscriptions","organizations_url":"https://api.github.com/users/mloayzagahona/orgs","repos_url":"https://api.github.com/users/mloayzagahona/repos","events_url":"https://api.github.com/users/mloayzagahona/events{/privacy}","received_events_url":"https://api.github.com/users/mloayzagahona/received_events","type":"User","site_admin":false},"created_at":"2016-02-13T18:09:00Z","updated_at":"2016-02-13T18:09:00Z","body":"Here the Apache rules\r\n\r\n```html\r\n<IfModule mod_rewrite.c>\r\n  RewriteCond %{REQUEST_FILENAME} !-f\r\n  RewriteCond %{REQUEST_FILENAME} !-d\r\n  RewriteRule ^(.+)\\.(\\d+)\\.(js|css|png|jpg|gif)$ $1.$3 [L]\r\n</IfModule>\r\n```\r\nI got this from this site [here](https://gist.github.com/varunachar/5335579#file-httpd-conf)\r\n\r\ndon't forget to enable mod_rewrite module.\r\n```apache\r\nLoadModule rewrite_module libexec/apache2/mod_rewrite.so\r\n```"}}