简体   繁体   English

降低包含多个JavaScript的成本

[英]Reduce the cost of Including Multiple javascripts

I have developed an application using backbone.js So I have created multiple models and multiple views. 我已经使用骨干.js开发了一个应用程序,所以我创建了多个模型和多个视图。 Initially I created them in one file but after some further reading, I came to know it is advisable to keep models separate, views separate and all routers separate. 最初,我将它们创建在一个文件中,但经过进一步的阅读后,我知道将模型分开,将视图分开并将所有路由器分开是明智的。 I just want to know, if we do this We will be increasing the number of HTTP Get requests (one for each javascript file) So this practice leads to some extra cost. 我只是想知道,如果这样做,我们将增加HTTP Get请求的数量(每个javascript文件一个),因此这种做法会导致一些额外费用。

Q. How can we reduce this cost ? 问:如何减少此成本?

I just came across to this question surfing something else and found this my own question. 我只是在浏览其他内容时遇到了这个问题,却发现这是我自己的问题。 If I were to answer this now, it would be this: 如果我现在要回答这个问题,那就是:

Keep your Models, Views, Routers etc in separate files but always merge them and then include link of merged file in your HTML code. 将模型,视图,路由器等保存在单独的文件中,但始终将它们合并,然后在HTML代码中包含合并文件的链接。

You can use some runtime JS minifier just like mentioned in this blog Minify JS runtime in PHP 您可以使用一些runtime JS minifier ,就像本博客中提到的使用PHP runtime JS minifier JS运行时

There are other online tools available too. 也有其他在线工具可用。

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

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