Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: FilesMatch |
|
Author |
|
MysteryFalcon
Joined: 01 Dec 2021 Posts: 3 Location: Stockholm
|
Posted: Wed 01 Dec '21 13:00 Post subject: FilesMatch |
|
|
I would like to turn on cache for specific .jpgs on a website, located in specific directories but I'm a bit uncertain how this would be done.
This is the structure I would like caching to apply to:
<FilesMatch "usr/*/[ALPHANUMERIC].jpg">
Does anyone know how to solve this? Help is much appreciated. |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
|
Back to top |
|
tangent Moderator
Joined: 16 Aug 2020 Posts: 348 Location: UK
|
Posted: Wed 01 Dec '21 17:34 Post subject: |
|
|
Rather than get into the complexity of setting up and managing server side cache resources (memory or disk), I've previously passed this requirement over to the client browser, to prevent repeat requests for the same static files.
In the global section of your configuration file put something like:
Code: | # Set cache control environment variables for selected file request types.
# These variables are used to conditionally set cache-control headers.
#
RewriteCond %{REQUEST_URI} (?i)\.(css|js)$
RewriteRule .* - [E=ShortCache:true,NE]
RewriteCond %{REQUEST_URI} (?i)\.(gif|jpg|jpeg|png)$
RewriteRule .* - [E=LongCache:true,NE]
RewriteCond %{REQUEST_URI} (?i)\.app$
RewriteRule .* - [E=NoCache:true,NE]
|
and then further down (global or vhosts) add the following (adjusting max-age to suit):
Code: | # Set cache control header for selected file types, with an expiry time of 2 hours
# for script files, 24 hours for image files, and no cache for application files.
#
Header set Cache-Control "max-age=7200" env=ShortCache
Header set Cache-Control "max-age=86400" env=LongCache
Header set Cache-Control "no-cache, no-store, must-revalidate" env=NoCache
Header set Pragma "no-cache" env=NoCache
|
Accepting this strategy does rather depend on your site content and function, but in the past I've found this approach make a signficant difference to server throughput. |
|
Back to top |
|
MysteryFalcon
Joined: 01 Dec 2021 Posts: 3 Location: Stockholm
|
Posted: Thu 02 Dec '21 16:36 Post subject: |
|
|
Many thanks for the help!! |
|
Back to top |
|
|
|
|
|
|