mwrock / RequestReduce

Instantly makes your .net website faster by reducing the number and size of requests with almost no effort.
www.requestreduce.org
Apache License 2.0
228 stars 49 forks source link

Disable ASP.NET response caching when Request Reduce has not compeleted reducing #190

Open candrews opened 12 years ago

candrews commented 12 years ago

If request reduce has not "done it's thing" for a given request (in other words, not all CSS/JS has been reduced yet), it should tell ASP.NET to disable response caching. That way, non-request reduced responses will not be cached at the browser, proxy, or IIS level.

My problem right now is that I have ASP.NET output caching enabled, so the first generated response is cached. And since it's the first response, RR has not done its magic yet, and the non-RR'ed response ends up cached and served for all subsequent responses - the RR content is never used.

To do disable caching, you'd do this:

Response.Cache.SetCacheability(HttpCacheability.Private);
mwrock commented 12 years ago

Great idea!

candrews commented 12 years ago

It seems that ResponseTransformer.DoTransform is where the magic happens.

I believe adding

Response.Cache.SetCacheability(HttpCacheability.Private);

at ResponseTransformer.cs line 143 resolves this issue.

candrews commented 12 years ago

Actually, that change is a bit too aggressive (it prevents caching of pages that could be cached).

If any resource being requested by RR has a near futures expires header or should otherwise being ignored by RR (it's in the JavaScriptUrlsToIgnore list), then ResponseTransformer.cs line 143 is always hit, and the page is never cached. So the fix for this issue has to take into account ignored urls.