Add a Version Parameter to the ScriptSrc URL in a ScriptLink CustomAction
July 6, 2012 1 Comment
The CustomAction element provides a great way to inject a JavaScript file into every page in a site collection or site without having to explicitly reference the file in a master page. You simply set Location to “ScriptLink”, specify the path to the JavaScript file in the ScriptSrc attribute and it will generate a script tag. This is particularly handy in situations where you may need script to execute in pages that don’t use your master page like the PerformancePoint application pages that open in a new window.
One problem you can run into with any JavaScript external script include is that users may be seeing stale versions of a script file. Whenever you update a script, you may find that need to have your users explicitly refresh the page to get the latest changes to the file. If they don’t refresh, they will likely be getting a locally-cached version of the file.If you use a ScriptLink control to add script tags to your page, it takes care of this problem for you. The ScriptLink control will automatically append a “rev” query string parameter to the URL of the referenced script file that contains a version ID for that file so when the script is updated on the server, the new query string parameter forces the browser to request the latest version of the file. The browser can then continue to serve this file from cache until the version on the server is updated again.
Read more of this post





