I'm developing a PHP application which uses Twig (but that's unimportant) as the view layer. This view layer has a custom extension which allows me to register both remote style and script assets as well as style and script inline blocks. The system holds on to these references until the page has completed rendering, placing all of the style directly before the tag, and all the scripts directly before the tag reference.
I've seen packagers like this on a few sites (DataExplorer for one). Here's a sample from vimeo:
<link rel="stylesheet" type="text/css" media="all" href="/assets/css/get/38402/global,lightbox,new_phome,stats_module" />
I'm trying to weigh the pros and cons (and here's where you guys come in!) of creating an asset packager (and minimizer) which will cache all of a page's dependencies into two file (js and css, respectively).
A few problems to consider:
Does this help performance if the user has to download sections of global.css because it is packaged on one page with login.css and packaged with another without it?
Is it necessary to compile these the first time as a user hits it (and, of course, cache afterwards), or is there a method to scrape each page and cache the minimized results as part of deployment开发者_运维技巧 so that that one user is never hit with such a long page load?
It's a while away from deployment; I just thought I'd get a few thoughts from you experts.
Ideally, you should pack your files into as few files as possible, including libraries and the like. And send them deflate compressed.
Each file creates another request, with which:
- A DNS query might be made,
- Cookies sent (if no static subdomain is used),
- Authentication mechanisms are triggered,
.htaccess
,php.ini
etc are checked
and tons of others. The overhead of this is generally exponentially greater than packing and sending them in a single compressed file. And with compression, file size and caching wouldn't be a problem.
You can find really many good pointers about this and other possible speed improvements for any web application at Google Speed (especially articles) and at Yahoo Performance.
精彩评论