browser-caching works except for svg-images - .htaccess

I'm having trouble with the browser-caching of SVG-files.
In my .htaccess, everything seems to be fine (at least it is rather complete) but no matter what I try, it seems as if the SVG-images aren't making their way into the browser's cache.
there's
<IfModule mod_expires.c>
ExpiresActive On
...
(various other file-types)
...
ExpiresByType image/svg+xml "access plus 1 month"
ExpiresDefault "access plus 1 month"
</IfModule>
in the .htaccess, I tried
ExpiresByType image/svg+xml A2592000
too, but nothing works. I also tried to change the mime-type to text/svg+xml. no good neither.
What could cause this failure?
Thanks

In line with the suggestion by #Ariel I checked my .conf files and I keep having the same issue, although I added
ExpiresActive on
ExpiresDefault "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 month"
ExpiresByType image/svg "access plus 1 month"
even if it is working (i assume) for svg fonts. I have no .htaccess, so everything is done in the .conf files. On that note i also have
<FilesMatch "\.(jpg|png|css|js|swf)$">
Header unset Cache-Control
</FilesMatch>
but as far as i know that wouldn't even touch the svg files. Thanks

Related

Cache policy in htaccess not being heeded to by reporting tools

There are many questions out there LIKE this PageSpeed Insights wrongly reporting cache policy But none address the issue of simply ignoring the cache policies that are stated by the .htaccess file. Normally I wouldn't worry so much about this, as our sites paint completely in under 2 seconds and user experience is great. But Management cares about pretty graphs and reports.
I have the following caching policies:
ExpiresActive On
# Images
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/webp "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType image/x-icon "access plus 1 year"
# Video
ExpiresByType video/mp4 "access plus 1 year"
ExpiresByType video/mpeg "access plus 1 year"
ExpiresByType video/m4v "access plus 1 year"
# CSS, JavaScript
ExpiresByType text/css "access plus 1 week"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
# Others
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
I want to point out one in particular since it makes it easy to point out the problem:
ExpiresByType video/m4v "access plus 1 year"
If you visit the site and view the headers for said file:
You can clearly see that the setting is being sent by header and is, thus, properly configured for a 1 year policy. HOWEVER .. When using Insights, OR Lighthouse individually they both report 30 days:
Not to mention all the other policies that are transferring properly in the header, but being completely ignored by LightHouse and Insights .. Does anyone have any answer for "why" this is happening? It's infuriating that even though the headers are obviously correctly sent, Lighthouse ignores them.
I have even tried something like this to no avail:
<filesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf|mp4|m4v|css|js)$">
Header set Cache-Control "max-age=31536000, public"
</filesMatch>
But I don't think that will make a difference, since the headers are, in fact, being sent correctly.

Permanently delete/remove blog-articles perhaps automatically with rule?

I have an articles-blog and my articles may have a shelf-life of perhaps 1-2 weeks max. In my .htaccess I already have ExpiresByType rules (but the clutter in my MODx backend is still there and I do not understand the impact of these rules - code is below). I also have put my articles standard as indexable by the search engines.
When the shelf-life expires, I would like to permanently delete my articles. Now I do this manually and I have a whole lot of "red-crossed-out" articles titles in my back-end which makes me completely loose the overview.
My question is: What is MODx EVO best practise for my situation and is there an "automatic" way to permanently and completely (so no more red-crossed-out resource titles) remove expired articles from my MODx backend with pre-defined rules (for example, "if published time-period on the internet is 20 days then delete/remove article from MODx backend/database)"?
## Leverage Browser Caching ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 2 days"
</IfModule>
## Leverage Browser Caching ##

.htaccess / mod_expires not working for sub directory

.htaccess file in the root directory and it is working perfectly fine for desktop users as the files for the desktop site are in the root directory but as for my mobile site the .htaccess file does not seem to work as the mobile site files are in a sub directory named m.
So basically I'm trying to add this code in .htaccess file
<IfModule mod_expires.c>
# Enable expirations
ExpiresActive On
# Default directive
ExpiresDefault "access plus 1 month"
# My favicon
ExpiresByType image/x-icon "access plus 1 year"
# Images
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
# CSS
ExpiresByType text/css "access plus 1 month"
# Javascript
ExpiresByType application/javascript "access plus 1 year"
</IfModule>
And when I check Google page speed test its working perfectly for desktop site but as for mobile it isn't so do I have to make a separate .htaccess file for the sub directory and if yes what do I have to add in that or can I just edit the current one so that it starts working for that m sub directory?
Only a partial answer, but the Apache web server documentation says that .htaccess files apply to the directory they are in, "and to all subdirectories thereof". So you shouldn't need to create a separate .htaccess for the m sub-directory, or do anything special in your original .htaccess to make it apply to the sub-directory.
Is your web server Apache? Perhaps other web servers treat .htaccess files differently.

add header expire for online script in htacess Magento

Hi i need to add aa header expiry in my magento site.
below is the script which needs to be add expiry
https://fonts.googleapis.com/css?family=Open+Sans:300,400,700
https://platform.twitter.com/widgets.js
https://ssl.google-analytics.com/ga.js
i have a folowing code in my htacess file
<IfModule mod_expires.c>
# Enable expirations
ExpiresActive On
# Default directive
ExpiresDefault "access plus 1 month"
# My favicon
ExpiresByType image/x-icon "access plus 1 year”
# Images
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
# CSS
ExpiresByType text/css "access 1 month”
# Javascript
ExpiresByType application/javascript "access plus 1 year"
</IfModule>
Please suggest me how can i add expiry for online scripts Thanks
As of my findings on your question, It is NOT POSSIBLE and it is not recommended also. Go through this How can I add expire headers for scripts that are not on my server?
You cannot set expiry headers or any headers to files that are served from a third party. Your options are:
Copy those files locally and set your desired headers
Keep it as is and ignore any reports saying headers missing or whatever
Only in rare cases I see advantage in using #1. Otherwise, your best bet is to leave it alone.

expiresByType exception for one folder?

I'm using the following line in my htaccess to set the expiration of my png files:
ExpiresByType image/png "access plus 1 month"
However, i need the png files in one exact folder to expire instantly. Is it possible to do this?
Yes, it should work if you put it in .htaccess file in that folder. Do not forget to add ExpiresActive On directive as well. For example:
Content of /images/special/.htaccess :
ExpiresActive On
ExpiresByType image/png "access plus 1 month"

Resources