Skip to content

Instantly share code, notes, and snippets.

@gorobey
Forked from mouse0270/rapidDefer.js
Created November 23, 2018 14:15
Show Gist options
  • Save gorobey/e5a87878461659d736e48eb45f15f5ac to your computer and use it in GitHub Desktop.
Save gorobey/e5a87878461659d736e48eb45f15f5ac to your computer and use it in GitHub Desktop.
Defer Inline Javascript
// With $script variable
$(document).ready(function() {
$('script[type="text/javascript/defer"]').each(function() {
var $script = $('<script type="text/javascript"/>').text($(this).clone().text());
$(this).after($script).remove();
});
});
// Without $script variable
$(document).ready(function() {
$('script[type="text/javascript/defer"]').each(function() {
$(this).after($('<script type="text/javascript"/>').text($(this).clone().text())).remove();
});
});
// Minified
$(document).ready(function(){$('script[type="text/javascript/defer"]').each(function(){$(this).after($('<script type="text/javascript"/>').text($(this).clone().text())).remove()})});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment