Skip to content

Instantly share code, notes, and snippets.

@zplume
Last active October 9, 2015 07:11
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
/*
Load non-minified version of JS if debug=1 is present in window.location.search.
This JS file can either be referenced in a master page with a <script> tag or via Custom Action.
Use of document.write ensures the script is inserted immediately below this one, synchronously.
For version string to successfully cache bust, the reference to this script also needs a query string that is updated each time this script is updated.
*/
(function() {
var minUrl = "/script.min.js",
debugUrl = "/script.js",
versionString = "?v=123456"; // cache-busting query string - to be updated when the JS file changes
function addScriptTag(url) {
document.write("<script type='text/javascript' src='" + url + versionString + "'></script>");
}
if (window.location.search.toLowerCase().indexOf("debug=1") > -1)
addScriptTag(debugUrl);
else
addScriptTag(minUrl);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment