Forum Discussion

Gerardo_Garcia_'s avatar
Gerardo_Garcia_
Icon for Nimbostratus rankNimbostratus
Nov 18, 2009

SharePoint Caching imgs, js, css

I need you help with an iRule

 

 

I need to add a header that will allow the cache of all the content type

 

application/javascript

 

image/gif

 

text/css

 

image/jpg

 

 

that includes in the URL

 

_layouts

 

_themes

 

 

The way that I think we need to do it is to create an iRule that will allow me to insert a header based on the content type and the URL.

 

 

The header that I need to insert is the

 

Expires:12/31/2035

 

Cache-Control:public

 

 

Can you help me with the iRule?

 

  • Hi Gerardo,

     

    Here is an untested example

     

     

     
     when HTTP_RESPONSE { 
      if { ![HTTP::header exists Cache-Control] and ![HTTP::header exists Expires] and [HTTP::header exists Content-Type] } { 
         switch -glob  [HTTP::header Content-Type] { 
          "application/javascript" - 
          "image/gif" -  
          "text/css"-  
          "image/jpg" { 
               HTTP::header insert "Expires" "12/31/2035" 
               HTTP::header insert "Cache-Control" "public" 
                           } 
           } 
       } 
     } 
     

     

     

    This assumes that the server response to the client doesn't contain the headers but does contain the Content-Type

     

     

    NOTE: I haven't tested the validity so you might have to play around with the code

     

     

    I hope this helps

     

     

    Bhattman