[Suggestion] Even lesser HTTP request by adding a "proxy" script

Well-known member

Currently, we have really neat CSS handling mechanism (css.php) which allow us to select multiple CSS files that we need to one single call. However, specific pages may require additional css or javascript, which goes beyond the initially defined package, and additional calls are added.

Suggestion: Introduce proxy.php and some basic javascript.

Each time a CSS is needed, template designer or addon developer "registers" a CSS link or JavaScript link with the system. Then, template system can grab all those and combine them into one single request, IE:

proxy.php looks at the css array, curl/or local lookup the files it doesn't know, combine the files in the order requested, gzip the package, store as a cache, and output the file. So long as the request string are the same (IE: version not changed), it just fetches from the cache.

Same thing can be done for javascripts.

This will reduce the HTTP request for main page by 3 (3 js requests vs 1 js request and 2 css requests vs 1 css request), and other subsequent pages by a various amount.

Active member

XenForo developer

For reference, the 2 CSS requests are by design. The first one loads all global CSS. The second one will load all page-specific CSS. We leverage very aggressive caching here, so this ensures that on the second page view, much less CSS is downloaded.

If we did it in one request, many pages would be redownloading all that global CSS.

We have thought about it for JS files, though it's trickier (and whether serving JS via PHP would be better for the server, I'm not sure).

Well-known member

For reference, the 2 CSS requests are by design. The first one loads all global CSS. The second one will load all page-specific CSS. We leverage very aggressive caching here, so this ensures that on the second page view, much less CSS is downloaded.

If we did it in one request, many pages would be redownloading all that global CSS.

We have thought about it for JS files, though it's trickier (and whether serving JS via PHP would be better for the server, I'm not sure).

Ah, okay; 2 CSS design makes sense then.
Serving JS via PHP in the above described method will most likely not add loads; the reason for that is because we'd be caching the (gzipped too) and stream_copy_to_stream the output, which takes virtually no resources (especially in comparison to fopen and fread).