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
Historic F5 Account
Here is an iRule I wrote a while back, hope it helps:
I called it suppress_304, I have not touched it in a while so, let me know if it works: These are datagroups you will need:
class cached_extensions { ".gif"
".js"
".bmp"
".png"
".css"
".jpg"
".JPG"
}
class no_cache_directives {
"private"
"no"
"max-age"
}
class cached_content_types {
"java"
"image"
"css"
"plain"
}
Below is the iRule:
rule suppress_304 {
when RULE_INIT {
0 - No, 1 - Yes.
set static::obey_response_headers 0
set static::cache_seconds 14400
}
when HTTP_REQUEST {
set inject_maxage 0
if { [class match [HTTP::uri] ends_with cached_extensions] } {
set inject_maxage 1
}
}
when HTTP_RESPONSE {
if {
not (
$static::obey_response_headers and
(
[class match [HTTP::header "Cache-Control"] contains no_cache_directives] ||
[HTTP::header exists "Expires" ]
)
)
and
(
$inject_maxage == 1 ||
[HTTP::query] eq "" and
[class match [HTTP::header "Content-type"] contains cached_content_types]
)
} {
HTTP::header replace Cache-Control "max-age=$static::cache_seconds"
}
}
TJ_Vreugdenhil
Aug 07, 2014Cirrus
This is a nice iRule, but it does not seem to meet the initial requirement:
"For images, the expires tag should live for 7 days. For css/js files, the expires tag should live for 24 hours"
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