JS load automatically
Posted: Wed Jul 01, 2009 7:54 pm
Everybody know js can be load dynamically
using this code :
I get a lot of speed benefit since i separate all my js to many file and some of them still messy by loading only the function i need in specific page
I use this function in my intranet application and I'm going to use it in my website soon, my question will there be a security threat using this method ? I understand I can use js minify ( I don't know how to do this ) or apache mod deflate some of them not working in the server site some time. so this is one of them to speed up things.
using this code :
Code: Select all
function addJS(json) {
//0 - for id
//1 - for url
var head = document.getElementsByTagName('head')[0];
for( var a = 0; a < json.length; a++ ) {
var JSAdd = document.createElement('script');
JSAdd.setAttribute('id',json[a][0]);
JSAdd.type='text/javascript';
JSAdd.src = json[a][1];
head.appendChild(JSAdd);
}
}I use this function in my intranet application and I'm going to use it in my website soon, my question will there be a security threat using this method ? I understand I can use js minify ( I don't know how to do this ) or apache mod deflate some of them not working in the server site some time. so this is one of them to speed up things.