Possible to add a cache setting for images that are XF attachments?

Kevin

Well-known member
In my .htaccess file I'm caching jpg images using something like...
Code:
<FilesMatch "\.(js|jpg|jpeg|png|gif|swf|svg)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
XF attachment file names though append the file ID to the end of the file, like https://mydomain.com/attachments/my-image-jpg.123/. Is there a way of being able to specify a mask (eg: https://mydomain.com/attachments/*) in htaccess to specify a cache life span? 🤔
 
OK, I think I see my problem... caching everything in the /attachments/ folder would work with \/attachments\/.+$ but https://mydomain.com/attachments/my-image-jpg.123/ is not a physical file but a route so the file is being retrieved for each request.

So is there a way of getting XF attachments to be cached in the browser? 🤔


EDIT: Looks like maybe something in my .htaccess is causing attachments not to be cached. Experimenting now...
 
Last edited:
<LocationMatch "^/attachments\/[^\.]+\-(js|jpe?g|jpfeg|png|gif|swf|svg)\.\d+\/?$">
Header set Cache-Control "max-age=604800, public"
</LocationMatch>

Haven't tested it, but it should work, that or the alternative without forward slashes escaped:

<LocationMatch "^/attachments/[^\.]+\-(js|jpe?g|jpfeg|png|gif|swf|svg)\.\d+/?$">
Header set Cache-Control "max-age=604800, public"
</LocationMatch>
 
@MySiteGuy I think the root issue I was having was something in my .htaccess with settings that date back several years. Cleaning out the .htaccess file and attachments seem to be getting served from the cache now in Chrome.

Thanks :)
 
Top Bottom