Struggling to control client-side caching with GetResource.ashx

Bryan Johnson asked on March 17, 2017 22:27

I'm struggling to control the cache-control response header property for a CSS file retrieved using GetResource.ashx in Kentico 10. I'd like to take advantage of the built-in compression feature offered by GetResource.ashx, but I'd also like to set the client-side cache expiration in the response header. According to the documentation it should be possible to control the cache-control property of the response header, but it doesn't seem to work. The response header still shows: cache-control:public, must-revalidate.

I'm seeing the problem for both CSS defined in the database and CSS files in the file system.

Here is my CSS link to CSS stored in the database: <link rel="stylesheet" href="/CMSPages/GetResource.ashx?stylesheetname=MyCSS" />

Trying a file, my key setting is:
<add key="CMSPhysicalFilesCacheMinutes" value="10080"/>

Here is my css link to a file:
<link rel="stylesheet" href="/CMSPages/GetResource.ashx?stylesheetfile=/App_Themes/MySite/css/main.min.css" />

Is there some other configuration necessary to accomplish what is described in the documentation? Or does this sound like a bug?

Correct Answer

Trevor Fayas answered on March 18, 2017 16:10

Can you copy and paste your header response parameters from the request?

I loaded up my Kentico 10 base install, and added a CSS link: /CMSPages/GetResource.ashx?stylesheetfile=/App_Themes/default/CMSDesk.css

Here's my headers

Cache-Control:public, must-revalidate
Content-Disposition:attachment; filename="CMSDesk.css"
Content-Length:76439
Content-Type:text/css
Date:Sat, 18 Mar 2017 15:05:57 GMT
ETag:"file|11/21/2016 5:32:00 AM"
Expires:Sat, 25 Mar 2017 15:05:57 GMT
Last-Modified:Mon, 21 Nov 2016 11:32:00 GMT
Server:Microsoft-IIS/7.5
X-AspNet-Version:4.0.30319
X-Frame-Options:SAMEORIGIN
X-Powered-By:ASP.NET

When i add the web.config key and set the expiration to 60, this is what i get:

<add key="CMSPhysicalFilesCacheMinutes" value="60"/>

Cache-Control:public, must-revalidate
Content-Disposition:attachment; filename="CMSDesk.css"
Content-Length:76439
Content-Type:text/css
Date:Sat, 18 Mar 2017 15:09:41 GMT
ETag:"file|11/21/2016 5:32:00 AM"
Expires:Sat, 18 Mar 2017 16:09:41 GMT
Last-Modified:Mon, 21 Nov 2016 11:32:00 GMT
Server:Microsoft-IIS/7.5
X-AspNet-Version:4.0.30319
X-Frame-Options:SAMEORIGIN
X-Powered-By:ASP.NET

As you can see, the expiration web.config is behaving as expected, it changed from 10080 to 60 minutes for the Expires tag... not sure why it's not working for you, what version are you on?

0 votesVote for this answer Unmark Correct answer

Recent Answers


Bryan Johnson answered on March 20, 2017 18:33

Thanks, Tevor. I didn't realize that the cache could be managed in that way. I expected the cache-control property to be updated with a max-age value. I'm seeing the same sort of behavior that you are seeing. So I guess its working correctly. Bryan

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.