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.