[英]Multiple Javascript files but only one HTTP request
I want to separate my JS out nicely so each object is in its own file, I'll probably structure my directories and files like: 我想很好地分离我的JS,所以每个对象都在自己的文件中,我可能会构建我的目录和文件,如:
/js/modules/module1.js /js/pages/page1.js /js/modules/module1.js /js/pages/page1.js
Problem is I don't want to have like 50 HTTP requests for each file, is there a way to do this? 问题是我不希望每个文件都有50个HTTP请求,有没有办法做到这一点?
This technique is quite basic and logical. 这种技术非常基础和合乎逻辑。 The situation is that we have several calls to external Javascript files within our HTML's header, which means several HTTP requests from the client's browser.
情况是我们在HTML的标题中有几个外部Javascript文件调用,这意味着来自客户端浏览器的几个HTTP请求。 How do we approach reducing all these HTTP requests?
我们如何减少所有这些HTTP请求?
Combine them so that there is at least only one call to an external Javascript file, Avoid breaking any Javascript-dependent functionality on the web page, Minify the Javascript to save on bandwidth 将它们组合起来,以便至少只有一次调用外部Javascript文件,避免破坏网页上任何依赖于Javascript的功能,缩小Javascript以节省带宽
http://falcon1986.wordpress.com/2010/01/11/combine-and-minify-javascript-reduce-number-of-http-requests/ http://falcon1986.wordpress.com/2010/01/11/combine-and-minify-javascript-reduce-number-of-http-requests/
Two ways came to my mind: 我想到了两种方式:
/scripts/all.js
, and on the request for that js, compile and merge all files and serve them. /scripts/all.js
,并在请求该js时,编译并合并所有文件并提供它们。 You can use a PHP file to serve all of them combined. 您可以使用PHP文件来组合所有这些文件。 This technique is used by many PHP softwares such as IP.board
许多PHP软件(如IP.board)都使用此技术
In case of ASP.NET, this will help - http://abhijitjana.net/2011/10/06/bundling-and-minification-in-asp-net-4-5/ 在ASP.NET的情况下,这将有所帮助 - http://abhijitjana.net/2011/10/06/bundling-and-minification-in-asp-net-4-5/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.