ERR_SPDY_PROTOCOL_ERROR reason and solution


I am using ngx_pagespeed on this website for quite sometime.ngx_pagespeed is port of Google pagespeed for Nginx web server.It was working great for me.I was using this configuration.I even tried it with HHVM .All the time and experimentation I never faced a single ngx_pagespeed issue.It was compatible with all things I tested.

Couple of months back I switched from HTTP to HTTPS.There were couple of reasons for this switch.First I added eCommerce section to this website.Second Google included HTTPS as ranking signal in its search algorithm.So I bought a SSL certificate and configured my Nginx server to use SSL.I configured Nginx server to use SPDY protocol.

After moving to SSL my Google Adsense revenue dropped.The trend continued for more than couple of weeks.It was getting tough to understand the reason.All the factors remained the same.One particular parameter caught my attention.The ad requests were not matching page views.There was too much of deviation.

I started exploring the reasons for it.After spending quite sometime investigating for the reason I was able to find it.I loaded this website on Google Chrome incognito window.The ads were not loading on the page.I refreshed the page and ads were loading.

Then I closed the window.Opened it again and found that ads are not loading.This time I opened Google Chrome developers tools and saw Failed to load resource: net::ERR_SPDY_PROTOCOL_ERROR message.It was pointing to Defer JavaScript file created by ngx_pagespeed.Below image shows the webpage and corresponding error message.



Now it was time to resolve the problem.I was not willing to make any changes to my ngx_pagespeed configuration.So I tried to remove SPDY protocol support from Nginx.Removing SPDY protocol was not good for performance.But it was better option then making changes in ngx_pagespeed configuration.

Removing SPDY from Nginx – Not Worked

I removed SPDY protocol support and again tried loading my web page.The ads were not loading.The same problem persisted.So it was not an issue of incompatibility of Google Adsense and SPDY protocol support in Nginx.The next step was to modify ngx_pagespeed.

Bypassing Adsense ads from ngx_pagespeed rewrite – not worked

I tried bypassing Google Adsense ads from PageSpeed processing.PageSpeed provides Disallow command for bypassing the resources.You can use wild card characters with it as well.So I used below PageSpeed Disallow commands

pagespeed disallow '*adsbygoogle.js';
pagespeed disallow '*google_ads*';

I used some variant to bypass Google Adsense ads from being processed by ngx_pagespeed.Above two will do the task but for my surety couple of more were added including the fully qualified URL of Google Adsense JavaScript file.After making above changes to Nginx configuration I again revisited the site.Note all the time I was browsing my website using Incognito window of Google Chrome.This time also the same problem occurred.Some how the problem was occurring for first time page was loaded.If the page was refreshed it was working fine.

Note above commands just say PageSpeed not to rewrite these JavaScript files.So problem is not with rewrite_javascript filter.After trying above solutions it was clear that problem was not with SPDY protocol nor with Nginx.Also Google Adsense ads cannot be bypassed.

pagespeed_no_defer Adsense – Worked

There was one more option not to defer Google Adsense ads.To do this pagespeed_no_defer should be added on Google Adsense JavaScript code.Now modifying Adsense ads is risky.Though this modification should not have been an issue.But this is grey area.

Google might not like me adding pagespeed_no_defer to adsense ads.But having said that it was not ill intentioned modification to Adsense ad code.So I went ahead and added pagespeed_no_defer to Adsense.Below is the modification I tried

<script pagespeed_no_defer="" async src="//"></script>

This did not worked for me.The problem was present.Then I modified the Adsense code again.Below is the modification I tried

<script pagespeed_no_defer="">
(adsbygoogle = window.adsbygoogle || []).push({});

This time the solution was working.I ran it for quite sometime and there was no issue reported from Google Adsense team.Also I do not see any problematic modification in above changes.But in case you are not willing to modify the ad code then you can follow the next solution.

Removing defer_javascript – Worked

The last thing I tried was to remove the defer_javascript filter from ngx_pagespeed configuration.This filter defers execution of JavaScript on web pages.The filter delays loading of JavaScript files.So pages are delivered to visitors faster.

On most websites this filter alone can boost page on load time significantly.In my case it was not too much of impact.Social Media button code is already programmed to load after on load.There are some files which I would have liked to defer.But revenue was more important than performance gain due to this filter.


Honestly the solution mentioned above is not perfect one.I would have liked to find a work around without disabling defer_javascript.But as mentioned above none of the solution worked for me.In case something worked for you do share.

I will be updating this post in future with any progress in this regard.

Leave a Comment