Forum Discussion
cache-control header response
Is there a way to set to intercept the http header response and set cache-control (i.e. set control-control: private and max-age of 7 days)
for ONLY static files specified?
Thanks!
Regards,
Traolly Xiong
12 Replies
- hoolio
Cirrostratus
Hi Trx,
You could use a datagroup of static file types and then check if the HTTP::path ends with one of those file types. Or you could look at the response Content-Type. You could then use HTTP::header to modify the cache headers in the response.
Which LTM version are you going to do this on?
Aaron - We are on version BIG-IP 9.4.5 Build 1049.10 Final. Will your approach work with this version? If we can modify the cache headers at the f5 level, we NO longer need caching configuration on our app servers or IIS web servers. This would be great and save time testing/debugging.
Regards,
TRX - hoolio
Cirrostratus
This should work fine on 9.4.5. You'd want to use matchclass and/or findclass to do the lookups against the datagroup(s).
Aaron - Thanks.
This worked for me.
if request is a static file, set cache control to be cached on the client machine for 7 days
if { [HTTP::header exists Content-Type] } {
switch -glob [HTTP::header Content-Type] {
"text/javascript" -
"text/css" {
HTTP::header replace "Cache-Control" "private, max-age=604800"
}
}
}
Regards
TRX - hoolio
Cirrostratus
Hi TRX,
If you define a string datagroup with the static content-types named static_content_types_class, you could use matchclass in v9 like this to do the lookup and rewrite:when HTTP_RESPONSE { if { [HTTP::header Content-Type] ne ""} { if {[matchclass [HTTP::header Content-Type] equals static_content_types_class]}{ HTTP::header replace "Cache-Control" "private, max-age=604800" } } }
Aaron - I think the class are only allowed in version 10.x correct?
I defined a class but can't save it.
ex)
class static_Files {
{"zip""rar""js""css""ppt""pptx""doc""docx""xls""xlsx""pdf""jpeg""jpg""png""gif"}}
I get an error "undefined procedure: class]...
Thoughts?
Regards,
TRX
- hoolio
Cirrostratus
A datagroup is a separate object from an iRule. You can define a datagroup in any LTM version under Local Traffic >> iRules >> Datagroup tab.
Aaron - Now would I just do something similar like this after creating it?
if { [matchclass $uri contains ] } {
do something....
}
TRX - hoolio
Cirrostratus
You can use this example:
http://devcentral.f5.com/Community/GroupDetails/tabid/1082223/asg/50/aft/1178933/showtab/groupforums/Default.aspx1250847
If you're on 9.4.3 or lower, add $:: to the datagroup reference in the matchclass command:
if {[matchclass [HTTP::header Content-Type] equals $::static_content_types_class]}{
Aaron - hoolio
Cirrostratus
That looks right. Do you see any TCL errors in the /var/log/ltm file? Did you update the name of the datagroup in the iRule to static_files_TRX?
Aaron
Recent Discussions
Related Content
* 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
