I am trying to load script
and link
using javascript.Previously I was using jquery
not I am removing jquery
from our project only using javascript.
previously I write like this
$('head link[data-reqjq][rel=preload]').each(function(){
var a = document.createElement('script');
a.async=false;
a.src=$(this).attr('href');
this.parentNode.insertBefore(a, this);
});
$(function(){
$('script[data-reqjq][data-src]').each(function(){
this.async=true;
this.src=$(this).data('src');
});
});
Now I am trying to load both things using javascript
.
like this but it is not loading
var elements = document.querySelectorAll('head link[data-reqjq][rel=preload]');
Array.prototype.forEach.call(elements, function(el, i){
var a = document.createElement('script');
a.async=false;
a.src=this.getAttribute('href');
this.parentNode.insertBefore(a, this);
});
var elements = document.querySelectorAll('script[data-reqjq][data-src]');
Array.prototype.forEach.call(elements, function(el, i){
el.async=true;
el.src=el.data('src');
});
here is my code