可以在iframe中共享javascript导入吗? [英] Possible to share javascript imports across iframes?

查看:122
本文介绍了可以在iframe中共享javascript导入吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web应用程序,它有几个iframe都需要导入相同的javascript库(例如jquery)。

I have a web application that has several iframes that all need to import the same javascript library (eg jquery).

有没有办法只加载一次并以某种方式在所有iframe中共享该数据?我宁愿不让我的页面加载缓慢,因为它为每个iframe加载相同的JS文件一次。

Is there a way to only load it once and somehow share that data across all the iframes? I'd rather not have my page load slowly because it is loading the same JS files once for every iframe.

谢谢!

编辑:人们说你不能分享来自iframe的数据,但是如果js导入都在命名空间中,那就说NAMESPACE然后iframe就像
那样NAMESPACE = parent .NAMESPACE

推荐答案

如果所有帧都加载了相同的js文件,那么现代浏览器(chrome,firefox,IE)应该只是从缓存中加载相同的文件...所以你不必一遍又一遍地重新加载同一个文件。如果您的页面加载时间很长,请考虑缩小您的javascript(通过使用其他程序使您的js文件更小)...这可以大大减少加载时间。

If all frames are loading the same js file, modern browsers (chrome, firefox, IE) should simply load the same file from the cache...so you don't have to re-load the same file over and over again. If your page load times are long, consider minifying your javascript (making your js files smaller through the use of another program)...this can greatly reduce load times.

这篇关于可以在iframe中共享javascript导入吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆