Sunday, June 26, 2011

SPDY Push HTML

‹prev | My Chain | next›

Up today, I try to address a small issue with SPDY server push in / node-spdy. When I push out HTML and subsequently request that page, I see:



SPDY server push works by pushing resources into the browser cache before a user requests it. I am fairly certain that things go wrong here by pushing without an associated content-type. Way back when, I thought the only required fields for server push were url, HTTP status and HTTP version. It seems that there is a third.

Although...

It only seems to be required for HTML. I wonder if adding something like the following to node-spdy would do the trick:
var PushStream = exports.PushStream = function(associated_cframe, c, url) {
// ...

this._headers = {
status: 200,
version: "http/1.1",
url: url
};

if (/\.html?$/.test(url))
this._headers["content-type"] = "text/html";

};
I have already seen that images and stylesheets work just fine without a content type. Until I know that something more sophisticated is required in node-spdy, why bother adding complexity?

But first, I need to try it out. Loading up the app in Chrome and then navigating to the first pushed page, I find:



Ah, much better. Checking out the SPDY tab in Chrome's about:net-internals, I find no request for the one.html page, just the server push into cache. And the three HTML pushes have the correct content type:
t=1309109914117 [st=  62]     SPDY_SESSION_PUSHED_SYN_STREAM  
--> associated_stream = 1
--> flags = 2
--> content-type: text/html
status: 200
url: https://localhost:3000/one.html
version: http/1.1
--> id = 2
...

t=1309109914121 [st= 66] SPDY_SESSION_PUSHED_SYN_STREAM
--> associated_stream = 1
--> flags = 2
--> content-type: text/html
status: 200
url: https://localhost:3000/two.html
version: http/1.1
--> id = 4
...

t=1309109914121 [st= 66] SPDY_SESSION_PUSHED_SYN_STREAM
--> associated_stream = 1
--> flags = 2
--> content-type: text/html
status: 200
url: https://localhost:3000/three.html
version: http/1.1
--> id = 6
And the the stylesheet is sent without a content type (and still applies just fine):
t=1309109914122 [st=  67]     SPDY_SESSION_PUSHED_SYN_STREAM  
--> associated_stream = 1
--> flags = 2
--> status: 200
url: https://localhost:3000/stylesheets/style.css
version: http/1.1
--> id = 8
Cool beans. I will push that into node-spdy this afternoon and call it a day for my chain at this point. Must write more SPDY Book.


Day #59

No comments:

Post a Comment