Search code examples
httphttp-headershttp-request

Possible to specify async files in headers?


So my timeline always looks like this

http://see.kirkstrobeck.com/TjQU/Screen%20Shot%202014-02-04%20at%206.40.14%20PM.png

The index.html loads and then asks for other files. I was thinking is there a way to have the headers that respond to the request say what files should come down? So it would look like this ..

http://see.kirkstrobeck.com/TjKl/Screen%20Shot%202014-02-04%20at%206.40.14%20PM.png

maybe something like ..

<?

header('fileGetRequest: /js/common.js');
header('fileGetRequest: /css/common.css');

?>

Solution

  • I don't know of a way of doing it today, but SPDY expands the Link header with rel=subresource for exactly this use.

    From Server Push and Server Hints:

    Server Hint is a mechanism where the server can notify the client of a resource that will be needed before the client can discover it. The server does not send the entire contents of the resource, but rather just the URL as an early part of a response. The client can then validate its cache (potentially even eliminating the need for a GET-if-modified-since), and will formally request the resource only if needed.

    HTTP/1.1 200 OK
    Cache-Control: private, max-age=0
    Content-Encoding: gzip
    Content-Length: 13847
    Content-Type: text/html; charset=UTF-8
    Date: Thu, 13 Jan 2011 17:47:12 GMT
    Expires: -1
    Server: FastServer1.0
    Link: <logic.js>; rel=subresource
    
    <html>
    <body>
      [ lots of content here ]
      <script src="logic.js" type="text/javascript></script>
    </body>
    

    Source of the example: SPDY - LINK rel=subresource

    If you know the client does not have the resource in cache, you may also want to consider Server Push, which saved the round-trip.

    Server Push is where the server pushes a resource directly to the client without the client asking for the resource. The server is making an assumption here that pushing the resource is desirable. Pushing a cacheable resource can be risky, as the browser might already have the resource and the push can be redundant.


    May, 2015 Edit

    HTTP/2 (based on SPDY, which is somewhat phased out) also has Push Requests (and the Link header).