Forum Discussion
Jeff_C_42204
Nimbostratus
Aug 01, 2007Irule to set expires headers for static conent
Hello Dev Central!
I have an IIS 6.0 server that is not setting the expires header (cache-control is set) which is causing a potential performance issue.
I would like to remedy th...
Rodrigo_EV_7869
Nimbostratus
Jul 05, 2008As more customers are beginning to use YSlow (http://developer.yahoo.com/yslow/ - a Firefox add-on integrated with the popular Firebug web development tool that analyzes web pages and tells you why they're slow based on the rules for high performance web sites) to better develop their sites and applications, I think this topic can become a little bit more important.
I haven't tried this out yet, but should it work?
when RULE_INIT {
300s=5min, 3600s=1hour, 86400s=1day, 604800=1week
set expire_content_300 0
set expire_content_3600 0
set expire_content_86400 0
set expire_content_604800 0
}
when HTTP_REQUEST {
set expire_content_300 [matchclass [string tolower [HTTP::path]] ends_with ::class_expire_content_300]
set expire_content_3600 [matchclass [string tolower [HTTP::path]] ends_with ::class_expire_content_3600]
set expire_content_86400 [matchclass [string tolower [HTTP::path]] ends_with ::class_expire_content_86400]
set expire_content_604800 [matchclass [string tolower [HTTP::path]] ends_with ::class_expire_content_604800]
}
when HTTP_RESPONSE {
if { $expire_content_300 == 1 } {
HTTP::header replace "Cache-Control" "max-age=300"
HTTP::header replace "Expires" "[clock format [expr ([clock seconds]+300)] -format "%a, %d %h %Y %T GMT" -gmt true]"
} elseif { $expire_static_3600 == 1 } {
HTTP::header replace "Cache-Control" "max-age=3600"
HTTP::header replace "Expires" "[clock format [expr ([clock seconds]+3600)] -format "%a, %d %h %Y %T GMT" -gmt true]"
} elseif { $expire_static_86400 == 1 } {
HTTP::header replace "Cache-Control" "max-age=86400"
HTTP::header replace "Expires" "[clock format [expr ([clock seconds]+86400)] -format "%a, %d %h %Y %T GMT" -gmt true]"
} elseif { $expire_static_604800 == 1 } {
HTTP::header replace "Cache-Control" "max-age=604800"
HTTP::header replace "Expires" "[clock format [expr ([clock seconds]+604800)] -format "%a, %d %h %Y %T GMT" -gmt true]"
} else {
HTTP::header replace Expires -1
}
}
Thanks,
-Rodrigo
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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
