Javascript - 多个外部文件

标签 javascript

我有一个从多个来源接收数据的页面,我需要创建一组处理程序文件来配置和显示不同类型的数据。可能有 10-15 种不同的数据,每种都有自己的显示逻辑。每个处理程序都会相当大,而不仅仅是一两个方法。

我正在尝试找出交付此类应用程序的最佳方式,我能看到的仅有两个选项是:

1) Create an individual handler file for each type of data and externally load it in when the page loads. The problem with this is obviously including 10-15 different javascript files probably isn't a smart idea. Would I need to compress all the handlers into one file, minify it and deliver it compressed?

2) Do all the configurations on the server before pushing the data to the user. Here the problem is that the JSON data pushed back could be very large (plus would include HTML) and put a lot of strain on the server.

谁能阐明如何最好地交付复杂的 JavaScript 应用程序?

最佳答案

其实我更喜欢你的第一个选项。

将这些 JavaScript 源文件合并并缩小为一个文件并缓存,让 Web 浏览器将它们缓存在客户端中,这意味着后续请求不需要下载这个合并缩小后的大文件,从而提高网站的性能和减少网络流量。

关于Javascript - 多个外部文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6212400/

相关文章:

javascript - 带有 json 数据的香蕉 Sprite js 动画(前进/后退和淡入淡出)

javascript - 为什么 Number ('' ) 和 Number ('null' ) 返回 0

打开新窗口后 Javascript 页面停止响应

javascript - 心理游戏js : create pattern and check user input

javascript - 模拟 - 旨在在 1 个节点上运行。 0 找到代替

javascript - 登录 Safari JavaScript 控制台

javascript - beforeShowDay 中的多次检查 - jQueryUI datepicker

javascript - 使用 JavaScript 与常规 HTML 创建 HTML 元素

javascript - 需要使用 fadeinDown 和 fadeOutDown 效果对单词进行动画处理

javascript - Fullpage.js 不在屏幕顶部