I have some css files that need to be generated dynamically (why is complicated, but it's necessary). The easy solution is to change the files to aspx files, and use <%= %> tags as needed to inject the values I want.
This works fine, until we get to caching. It seems that the browser and server refuse to cache the file. I've tried manipulating the various http cache headers, but the browser always re-gets the file on each page load. The server always responds with HTTP 200 (and the correct content), rather than with a 304 (file unchanged).
How can I convince the browser and the server to cache these dynamic css files?
Example consuming file:
<html> <head> <link href="/style.aspx" type="text/css" rel="stylesheet"/>
...
Example style sheet, with cache header manipulation (omitting dynamic part of file):
<%@ Page Language="C#" ContentType="text/css" EnableSessionState="False" %>
<%
Response.Cache.SetLastModified(new DateTime(2009, 11, 18, 10, 1, 0));
Response.Cache.SetMaxAge(TimeSpan.FromDays(30));
Response.Cache.SetETag("4ffff353ff67ff1:0");
%>
...css here...
The request headers to the server includes the following:
If-Modified-Since Wed, 18 Nov 2009 18:01:00 GMT
Cache-Control max-age=0
And the related server response headers are:
Cache-Control private, max-age=2592000
Last-Modified Wed, 18 Nov 2009 18:01:00 GMT
Date Wed, 18 Nov 2009 19:36:07 GMT
Any ideas?