1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'XenForo Suggestions' started by Andy Huang, Oct 14, 2010.

  1. Andy Huang

    Andy Huang 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:
    <link rel="stylesheet" type="text/css" href="proxy.php?css[]=css.php&amp;#63;css=xenforo,form,public&amp;amp;style=1&amp;amp;d=1286902466&amp;css[]=css.php&amp;#63;css=attachment_editor,editor_ui&amp;amp;style=1&amp;amp;d=1286902466" /> 
    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.
    Luciano, krstep, ankurs and 4 others like this.
  2. random

    random Active Member

    I don't have any idea of what Andy is talking about :D but I support his suggestion!
    krstep and CFodder like this.
  3. Mike

    Mike XenForo Developer Staff 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).
  4. Andy Huang

    Andy Huang Well-Known Member

    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).
  5. Erik

    Erik Well-Known Member

    I'm pretty sure WordPress uses a similar "registering" system to ensure that any given CSS or JavaScript file is not included in the page more than once (it also handles dependencies). :)

Share This Page