Forum Discussion
Brett_Channon_1
Nimbostratus
Aug 29, 2006cache based on content type
Hi all,
I wrote this in a bit of a hurry (can you tell!) and figure there must be a better/more efficient way of writing this..
when HTTP_RESPONSE {
if { [HTTP::header Content-Type] contains "image/" } {
HTTP::header replace Cache-Control public,max-age=604800,must-revalidate,proxy-revalidate
} elseif { [HTTP::header Content-Type] equals "text/css" } {
HTTP::header replace Cache-Control private,max-age=604800,must-revalidate,proxy-revalidate
} elseif { [HTTP::header Content-Type] equals "application/x-javascript" } {
HTTP::header replace Cache-Control private,max-age=604800,must-revalidate,proxy-revalidate
} else {
HTTP::header replace Cache-Control private
}
}
Since the javascript and css content types can be treated the same I'm sure there's a better way of coding this particular part. Also, rather than set the header to be 'private' if the content type doesn't match I want to just leave it as is..
Thanks
Brett
- unRuleY_95363Historic F5 AccountI would try a switch:
when HTTP_RESPONSE { switch -glob [HTTP::header Content-Type] { *image/* { HTTP::header replace Cache-Control public,max-age=604800,must-revalidate,proxy-revalidate } text/css - application/x-javascript { HTTP::header replace Cache-Control private,max-age=604800,must-revalidate,proxy-revalidate } default { HTTP::header replace Cache-Control private } } }
However, this is slightly less efficient because the HTTP::header command still has to be evaluated multiple times.... } elseif { ( [HTTP::header Content-Type] equals "text/css" ) or ( [HTTP::header Content-Type] equals "application/x-javascript" ) } { HTTP::header replace Cache-Control private,max-age=604800,must-revalidate,proxy-revalidate } else { ...
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects