简体   繁体   English

防止多次下载相同的JavaScript库

[英]Prevent downloading of same JavaScript library multiple times

I have a scenario in which a container HTML page is including most of the common JS frameworks like JQuery, AngularJS, Bootstrap. 我有一个场景,其中容器HTML页面包括大多数常见的JS框架,例如JQuery,AngularJS,Bootstrap。 This page will then include other widgets in it through Ajax call using JQuery and if those widgets come with any of these common frameworks, the application/events of duplicated framework stopped working. 然后,该页面将通过使用JQuery的Ajax调用在其中包含其他小部件,并且如果这些小部件随附于这些常见框架中的任何一个,则重复框架的应用程序/事件将停止工作。

Now is there any way to prevent downloading of common frameworks from these widgets? 现在有什么方法可以防止从这些小部件下载通用框架?

Can this be handled through RequireJS? 可以通过RequireJS处理吗?

Just to get the idea: 只是想知道:

if (!sessionStorage.isLoaded)
{
    //load
    var fileref=document.createElement('script');
    fileref.setAttribute("type","text/javascript");
    fileref.setAttribute("src", filename);
    fileref.onload = function(){
      sessionStorage.isLoaded = 1;
    };
    document.getElementsByTagName("head")[0].appendChild(fileref);

}

check for ie compatibility http://www.nczonline.net/blog/2009/07/28/the-best-way-to-load-external-javascript/ 检查兼容性http://www.nczonline.net/blog/2009/07/28/the-best-way-to-load-external-javascript/

It's better off to unset sessionStorage.isLoaded beforeOnLoad :) 最好取消设置sessionStorage.isLoaded beforeOnLoad :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM