Home >Web Front-end >JS Tutorial >Use javaScript to dynamically load Js files and Css files_javascript tips
JS dynamic loading of CSS is of great significance in the theme-changeable interface. Users can choose their favorite page display method according to their browsing habits, as explained in detail below.
I hope the following method will be helpful to you.
(1) Use JavaScript to dynamically load Js files
/*JavaScript动态加载Js文件*/ var scriptNode = document.createElement('script'); scriptNode.src = 'proxy.js?t='+new Date().getTime();/*附带时间参数,防止缓存*/ document.head.appendChild(scriptNode);
(2) Use JavaScript to dynamically load css files
/*JavaScript动态加载Css文件*/ var cssNode = document.createElement('link'); cssNode.rel = 'stylesheet'; cssNode.type = 'text/css'; cssNode.media = 'screen'; cssNode.href = 'style.css?t='+new Date().getTime();/*附带时间参数,防止缓存*/ document.head.appendChild(cssNode);
The above is how to use javaScript to dynamically load Js files and Css files. I hope it will be helpful to everyone's learning.