Skip to content

Instantly share code, notes, and snippets.

@zplume
Last active October 9, 2015 07:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zplume/bfae9cdbc2b04917f8ac to your computer and use it in GitHub Desktop.
Save zplume/bfae9cdbc2b04917f8ac to your computer and use it in GitHub Desktop.
/*
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