-
Notifications
You must be signed in to change notification settings - Fork 0
/
lazyLoadScripts.js
38 lines (38 loc) · 1.34 KB
/
lazyLoadScripts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'use strict';
(function($) {
$(document).ready(function() {
/**
* LazyScriptLoader
*
* @author Gabriel Kaufmann <[email protected]>
*
* @example
*----------------------------------------------------------------
* For use with footer-libs not available for body-scripts.
* Use the lazy-load feature to automatically fire these scripts
* in place you want it!
*
* <script type="lazy@text/javascript">
* alert('footer-libs already waiting!');
* </script>
*----------------------------------------------------------------
*/
var lazyLoader = function() {
(function($) {
$('script[type^="lazy@"]').each(function() {
var $script = $($(this).get(0).outerHTML);
$script.attr({
'type': $script.attr('type').replace('lazy@',''),
'lazy': 'true'
});
$(this).replaceWith($script);
});
}) (jQuery);
};
if(document.readyState === 'ready' || document.readyState === 'complete') {
lazyLoader();
} else {
document.addEventListener('DOMContentLoaded', lazyLoader(), false);
}
});
}) (jQuery);