确定组合的 js 文件中包含哪些脚本

发布于 2024-09-30 08:11:13 字数 233 浏览 0 评论 0原文

我正在尝试构建一个ajax脚本加载器,但是我遇到了一个问题,我将组合文件的各个部分发送了两次以上(即jquery与其他脚本捆绑在一起,因为需要而发送了两次以上)通过一些(ajax)请求的脚本通过网络发送,

我的第一个想法是我只需将 md5 块附加到文件名上,如果请求的脚本与其中的一部分匹配,则不要发送 - 但这不能很好地扩展。比方说.. 100 个捆绑脚本。

还有其他建议吗?

谢谢

I'm trying to build an ajax script loader, but I'm running into the issue where I'm sending pieces of my combined file over twice (ie. jquery, bunched up with other scripts, is getting sent over twice because it's required by some (ajax) requested script sent over the wire.

My first thought was that I would just append md5 chunks onto the file name and if the requested script matches a piece of that, don't send - but this doesn't scale well for say.. 100 bundled scripts.

Anyone have any other suggestions?

Thanks!

Matt Mueller

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

把昨日还给我 2024-10-07 08:11:13

我认为这取决于脚本类型。就我个人而言,我会定义可用的库,然后测试该对象是否已定义。

这里的 WAG 示例,就在我的脑海中(在我看来,定期使用这种方法可能非常令人发指,但比单独识别文本要快。)

//javascript loader shell
var loader = function(){

    var loadLibrary = function(libraryName, fn){
        //your code to verify and download library or collection here 

        //callback function
        return fn();
    }

    return {
        exec: function(libraryName, fn){
           if(typeof(eval('window.'+libraryName)) != 'undefined'){
               return fn();
           } else {
               return loadLibrary(libraryName, fn);
           }
        }
    }   
}();

//example usage
loader.exec('util', function(){util.test();});

I think it depends on the script types. Personally I'd define the libraries that are available and then just test to see if the object has been defined.

WAG example here, just off the top of my head (in my opinion this method could be pretty heinous to use on a regular basis but would be faster than individually identifying text.)

//javascript loader shell
var loader = function(){

    var loadLibrary = function(libraryName, fn){
        //your code to verify and download library or collection here 

        //callback function
        return fn();
    }

    return {
        exec: function(libraryName, fn){
           if(typeof(eval('window.'+libraryName)) != 'undefined'){
               return fn();
           } else {
               return loadLibrary(libraryName, fn);
           }
        }
    }   
}();

//example usage
loader.exec('util', function(){util.test();});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文