Leverage browser caching on script SRC - .htaccess

I keep getting a 'leverage browser caching' error when I running pagespeed insight
This is what it complains about -
<script src="https://company.blogspot.com/feeds/posts/summary?
orderby=published&max-results=5&alt=json-in-script&callback=mycallback">
</script>
I've tried settting a fe thing in the .htaccess file but nothing seems to work -
<If "%{QUERY_STRING} =~ /orderby(.*)">
Header set Cache-Control "max-age=31535999, public"
</If>
Any help to fix this would be greatly appriciated. thanks

Related

Why is gzip not working on pub/static folder?

I am currently running Magento 2.1.14 and have enable gzip per the Magento documentation as well as the other well visited posts on this site. I have also doubled checked with my hosting provider that Mod_deflate is enabled on the server side.
In addition, I have a copy of my site on my local machine with same htaccess files as what resides on our live server.
On my local machine, simply enabling the apache module and then adding the htaccess code in the main htaccess file of the public_html directory works. All requests on my local site show headers that contain “Content Encoding: gzip”.
However, when live using https on our server, the gzip encoding seems to stop at the pub directory. NO content coming from the pub directory (pub/static and pub/media) shows and gzip encoding. The files on my local machine and live server are the same. According to my hosting provider, gzipped is enabled on their side and they believe that is has to do with one of the htaccess files in my file tree that is stopping the gzip encoding from happening.
I did a small test recommended by our hosting provider as well, and tried to set up an extra directory in the public_html directory on both my local machine and the live server to test if the gzip encoding would work. On my local machine, I can visit the directory and the file in it shows gzip compression, but on my live server, when adding the file to my public_html directory and attempting to visit it through the browser, Magento throws a 404 error!
Does anyone out there have any idea why gzip would not waterfall through my file tree and properly gzip the js, minified js, css and minified css files that are located in the pub folder?
After days of debugging it turns out that on my live server, the RequestHeader for Set-Encoding was being stripped. This was not happening on my Apache setup on my local machine. My web host still has not give me an explanation why this was happening, nor do I know if it has to do with the htaccess file in the pub/static directory, but adding the RequestHeader set below:
<IfModule mod_headers.c>
Header set X-UA-Compatible "IE=edge"
Header set Connection keep-alive
#THE LINE BELOW THIS COMMENT
RequestHeader set Accept-Encoding "gzip, deflate, br"
<FilesMatch "\.(appcache|atom|bbaw|bmp|crx|css|cur|eot|f4[abpv]|flv|geojson|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|topojson|tt[cf]|txt|vcard|vcf|vtt|webapp|web[mp]|webmanifest|woff2?|xloc|xml|xpi)$">
Header unset X-UA-Compatible
</FilesMatch>
to the htaccess file in the root of my magento site fixed the issue with the compression.
If this is a server issue, I would like someone to comment below on what I might bring up with my webhost to address this. Otherwise, I'm going to submit an issue to the Magento github.
Very strange issue,
deflate mode included in .htaccess of pub/static
bat not for all file types,
javascript files not added to setting
so,
just edit pub/static/.htaccess
and edit row with start - AddOutputFilterByType DEFLATE
and add content type -
text/javascript application/javascript application/x-javascript application/json image/svg+xml
now, all static content will with gzip.
Strange, why was missed this,
maybe for other features ?

How to Force Download files via .htaccess

I am trying to make my site "www.suruleretv.co" files like mp3, mp4 to force download instead of streaming.
I've tried to add some codes in find online via .htaccess but am getting error after adding it.
<FilesMatch "\.mp3$">
ForceType application/octet-stream
Header set Content-Disposition attachment
</FilesMatch>
it would help if you could add your code to the question, to clarify what you want and to identify what the issue is.
However, if you want to force files to be downloaded, adding the following in your .htaccess should be enough:
<FilesMatch "\.(mp3|mp4)$">
ForceType application/octet-stream
Header set Content-Disposition attachment
</FilesMatch>
Please keep in mind, that if you only add this part and have nothing else in it, you will have to save your .htaccess file in the same directory as the downloadeable files. It won't work for subfolders, without adding more rules.

WOFF2 - HTTP Content-Type response header suggestion

I'm doing some website optimisations using PageSpeed. I faced a next suggestion:
The following resources have no character set specified in their HTTP
headers. Specifying a character set in HTTP headers can speed up
browser rendering.
http://localhost:8892/.../FocoBold.woff2
http://localhost:8892/.../FocoRegular.woff2
http://localhost:8892/.../GTblack.woff2
I've instantly started google and found a relevant answer on StackOverFlow.
I've added next line to .htaccess but it didn't worked for me.
AddDefaultCharset UTF-8
Next thing I've tried, but still no results.
AddType font/woff2 .woff2
Can anyone help me with that?
Thank you in advance
I was having the same problem.
I think that pagespeed is misreporting the underlying cause which is not so much a lack of definition of the charset, but a lack of definition of the content-type. Without that's being defined, it / most browsers assume what is being sent back is text/html, where, indeed, no charset has been defined, especially as the .woff2 file will contain "non-standard" (ASCII!) chars.
My solution (it may not work if your apache environment is significantly different, such as not allowing addtype in .htaccess files) was to add the following to the .htaccess in the relevant root of the site being served:
AddType application/x-font-woff2 .woff2
(Found this resource)
Worked for me!
.htaccess
In .htaccess AddType should be in mod_mime.c module
<IfModule mod_mime.c>
AddType application/woff2 .woff2
</IfModule>

Header set Access-Control-Allow-Origin "*" not working

I've been trying to get this working for the last 3 days.
I have a WordPress site hosted with 1and1. I'm using the w3 total cache along with my rackspace cloudfiles account. All theme files are hosted from the cdn (css, fonts etc). This works fine in all but IE and FF. Reading further into it on SO this is a widely known issue. So, following this answer I've added the following to my htaccess file under both the site root, the fonts directory and the css directory.
<FilesMatch "\.(ttf|otf|eot|woff)$">
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
</FilesMatch>
I've also hard coded my cdns path to my font like this:
#font-face {
font-family: 'LeagueGothicRegular';
src: url('http://112k3jh1g23kj1g23kjhg12k3hg1kj2g3h1g-r93.rackscdn.com/mysite/wp-content/themes/mytheme/css/fonts/League_Gothic.eot?') format('eot')...
The cdn is serving the correct files, this all works in chrome but still web fonts DO NOT work in firefox and IE.
What am I missing?
I managed to solve this by base64 encoding the fonts in the the CSS. Hope this helps someone.

firefox and fontface htaccess

To make font-face work on FF I need to make a .htaccess file, upload it to the root directory and that should be it right?
so in a blank text file i write:
<FilesMatch "\.(ttf|otf|eot)$">
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
</FilesMatch>
I save it, I upload it to the site root and rename it to .htaccess
but it is not working, no matter what I do..
The strangest thing is that ff loads the fonts on some of the pages but not on all
Is there something else that should be added to the text/htaccess file?
Using htaccess as mentioned above did not solve anything, it actually just made things worse.
The solution was to make all paths relative.
I mean, EVERY path related to the fonts.

Resources