Forum Discussion
TJ_Vreugdenhil
Aug 06, 2014Cirrus
expires header for images iRule v11.x
For all images, we need to implement the expires tag to tell the users’ browser if they already have the image, that they can use that cached version for X hours.
For images, the expires tag should...
John_Alam_45640
Aug 10, 2014Historic F5 Account
I made the expiration duration dynamically assigned from the datagroup value field as your requirements show.
I also adjusted how the extension is obtained to make a more accurate decision. I did so by inspecting the [URI::basename [HTTP::uri]] rather than the entire [HTTP::uri] which could contain a query and parameters. Even though css and image links usually do not contain queries, it does not hurt to be accurate.
NOTE: I did not test the changes I made. If you can test and let us know it would be great.
ltm data-group internal /Common/class_cacheable_file_types {
records {
".css 86400"
".js 86400"
".bmp 604800"
".gif 604800"
".jpeg 604800"
".jpg 604800"
".png 604800"
".ico 604800"
}
type string
}
ltm data-group internal /Common/no_cache_directives {
records {
"private"
"no"
"max-age"
}
}
ltm data-group internal /Common/cached_content_types {
records {
"java"
"image"
"css"
"plain"
}
}
rule suppress_304 {
when RULE_INIT {
0 - No, 1 - Yes.
set static::obey_response_headers 0
}
when HTTP_REQUEST {
set inject_maxage 0
set cache_seconds [class lookup [URI::basename [HTTP::uri]] ends_with /Common/class_cacheable_file_types ]
if { not ($cache_seconds equals "") } {
set inject_maxage 1
}
}
when HTTP_RESPONSE {
if {
not (
$static::obey_response_headers and
(
[class match [HTTP::header "Cache-Control"] contains /Common/no_cache_directives] ||
[HTTP::header exists "Expires" ]
)
)
and
(
$inject_maxage == 1 ||
[HTTP::query] eq "" and
[class match [HTTP::header "Content-type"] contains /Common/cached_content_types]
)
} {
HTTP::header replace Cache-Control "max-age=$cache_seconds"
}
}
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