How: Caching of static files in Blob's?

Vote:
 

Hello

I followed the guidelines for caching and have set both clientCache within staticContent and each extension profile under caching to 30.00:00:00. Nevertheless, when I look at requests in HttpFiddler or YSlow, images that are within globalassets don't pick up the value. Is there a way to extend expire date to those as well.

Example 1, file within globalassets:

HTTP/1.1 200 OK
Cache-Control: public
Content-Type: image/jpeg
Expires: Wed, 16 Jul 2014 00:08:29 GMT
Last-Modified: Thu, 03 Jul 2014 13:11:02 GMT
Accept-Ranges: bytes
ETag: "1CF96C03D378650"
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Tue, 15 Jul 2014 12:08:29 GMT

Example 2, image from other location in site structure:

HTTP/1.1 200 OK
Cache-Control: public,max-age=2592000
Content-Type: image/jpeg
Last-Modified: Fri, 04 Jul 2014 16:55:16 GMT
Accept-Ranges: bytes
ETag: "4d5ec6baa897cf1:0"
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Tue, 15 Jul 2014 12:13:33 GMT

Obviously files within globalassets get Expires header set from somewhere, I just cannot find where. Any help? Thanx!

#88510
Jul 15, 2014 14:15
Vote:
 

Hi Milos,

Images from global assets folder are served by EPiServer.Web.StaticFileHandler.

I've checked the source code. It will try to read staticFile section from web.config and read expirationTime value.

So, inside your web.config file, make sure that you've defined staticFile section:

and set some value for epirationTime:

Hope this helps!

#88512
Jul 15, 2014 15:58
Vote:
 

Thanks, helped somewhat

With registering EpiServer.Framework.Configuration.StaticFileSection files from globalassets and contentassets got Cache-control set to public but real Expires: header was not outputed so it was unlimited caching without any control.

To get everything neat and tidy removing of caching profiles for desired extensions is a must. After that complete response is outputed

---- removed ----


  
    
    ...
    ...
  

---- removed ----

HTTP/1.1 200 OK
Cache-Control: public
Content-Type: image/jpeg
Expires: Wed, 15 Oct 2014 17:05:01 GMT
Last-Modified: Thu, 03 Jul 2014 11:17:27 GMT
Accept-Ranges: bytes
ETag: "1CF96B05F523FB0"
Server: Microsoft-IIS/8.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Thu, 17 Jul 2014 17:05:00 GMT
Content-Length: 5894

Now even YSlow doesn't complain there.

#88585
Edited, Jul 17, 2014 19:14
Vote:
 

I'm using the solution Dejan mentioned without removing the profiles (don't think the profiles has anything to do with the stuff being served by EPiServer.Web.StaticFileHandler) and it works for me with expires headings:

HTTP/1.1 200 OK
Cache-Control: public
Content-Type: image/jpeg
Expires: Thu, 16 Oct 2014 10:35:20 GMT
Last-Modified: Thu, 04 Sep 2014 08:37:30 GMT
Accept-Ranges: bytes
ETag: "1CFC81B76CF4100"
Server: Microsoft-IIS/8.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Mon, 06 Oct 2014 10:35:20 GMT
Content-Length: 23851

#91449
Oct 06, 2014 12:37
Vote:
 

I'm using the solution Dejan mentioned by just put staticFile configuration and it's work as expected.

#112511
Oct 29, 2014 11:17
Vote:
 

Hi Dzung and Dejan,

where can I add staticfile Section.

I am using a custom blob provider.

Default expiration for globalassets in fiddler is 12 hours.

I am getting this error.

The configuration section 'staticFile' cannot be read because it is missing a section declaration

trying following settings

<location path="Global">
<staticFile expirationTime="365.00:00:00" />
</location>

any help?

Regards
Khurram

#113542
Nov 24, 2014 13:06
Vote:
 

Hi Khurram,

I think first you need to insert

<section name="staticFile" type="EPiServer.Framework.Configuration.StaticFileSection, EPiServer.Framework" allowLocation="true" />

in configSections.

After that you can just use <staticFile expirationTime="365.0:0:0" /> same level as location. Then you could also add <staticFile expirationTime="365.0:0:0" /> beneath your location config section.

Hope this helps

#113575
Nov 25, 2014 6:01
Vote:
 

Many thanks Dzung It worked. in Section name i was using StaticFile rather staticFile. 
Regards
/K

#113596
Nov 25, 2014 13:19
Vote:
 

Glad its helps you. It took me quite sometime to find out this when upgrade from 6 to 7.5.

#113637
Nov 26, 2014 3:20
Vote:
 

Anyone been able to use above configuration to get a max-age=x part into the Cache-Control value?

Troubleshooing an issue with long lived cached PDF files now and just having Expires set seems to not be enough.

#171264
Nov 04, 2016 8:31
Vote:
 

@Johan I am also trying to do this. I would rather use Cache-Control with mad-age instead of expirationTime

#173831
Jan 10, 2017 17:36
Vote:
 

Thomas and Johan, AFAIK, changing the way EPiServer sets cahcing headers for media files, would require switching out how the cache policy is set in the MediaHandlerBase HttpHandler base class, but the way it is currently implemented, that would mean you'd have to switch out the internal ContentMediaHandler.

Personally, I'd rather have episerver open up an extension point where I could configure how cache headers should be sent.

I haven't tried switching it out myself, but maybe it's possible using a TemplateDescriptor(Inherited = true, TemplateTypeCategory = TemplateTypeCategories.HttpHandler) and replace the default implementation.

#174940
Feb 08, 2017 11:45
Vote:
 

Hi

I have the same issue as Milos described above. Currently I'm testing on IIS express Episerver 9 with blob storage in azure. I am currently only seeing "Cache-Control: public" and "Expires: xx" on .gif and .svg files from globalassets. I have not knowingly done anything to remove jpeg caching wise, but would very much like jpeg to be included as well.

Here are the key bits from my web.config:

<configSections>
...
<section name="staticFile" type="EPiServer.Framework.Configuration.StaticFileSection, EPiServer.Framework" allowLocation="true" />
</configSections>

<system.web>
...
<caching>
<outputCache enableOutputCache="true"></outputCache>
<outputCacheSettings>
<outputCacheProfiles>
<add name="ClientResourceCache" enabled="true" duration= "3600" varyByParam="*" varyByContentEncoding="gzip;deflate" />
<add name="CacheOneHour" enabled="true" duration="3600" varyByParam="*" varyByContentEncoding="gzip;deflate" />
</outputCacheProfiles>
</outputCacheSettings>
</caching>
<system.web>

<staticFile expirationTime="12:0:0"></staticFile>


Any hints on how to troubleshoot this?

#175808
Edited, Mar 02, 2017 15:54
Vote:
 

Episerver article about the issue: http://world.episerver.com/kb/159734

#177259
Apr 06, 2017 11:13
Vote:
 

@Simon

You should move <staticFile... /> into new <location> section as below.

<configuration>
  </configSections>
    ….
    <section name="staticFile" type="EPiServer.Framework.Configuration.StaticFileSection, EPiServer.Framework" allowLocation="true" />
  </configSections>
…
  <location path="globalAssets" >   
    <staticFile expirationTime="12:0:0" />
  </location>
</configuration>
#177765
Apr 19, 2017 6:36
Vote:
 

What EPiServer-version do you get this to work with? I'm using 10.4.3 and tried exactly the config that Kim Dung Nguyen suggested. But it doesn't work for me. No changes at all what I can see.

#183238
Oct 09, 2017 15:45
Vote:
 

I had it working in both 9 and 10 but in the end we switched to use https://github.com/bjuris/EPiServer.CdnSupport instead. Easier to grasp and tweak.

#183254
Oct 09, 2017 20:11
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.