GZIP Compression Not Working For Wordpress Site - php

I'm implementing a website in wordpress. When I test my site on google page speed, It's looking horrible. I'm getting some compression issues.
Compressing https://static.xx.fbcdn.net/rsrc.php/v2/yK/r/XVnmkWxbmyb.js could save 152KiB (74% reduction).
Compressing https://static.xx.fbcdn.net/rsrc.php/v2/yz/r/7emJbLsMYck.js could save 123.6KiB (72% reduction).
Compressing https://static.xx.fbcdn.net/rsrc.php/v2/yY/r/MYnSaHkqljr.js could save 121.7KiB (70% reduction).
Compressing https://static.xx.fbcdn.net/rsrc.php/v2/yh/r/Sst4Eu6wCBO.js could save 69.3KiB (70% reduction).
Compressing https://static.xx.fbcdn.net/rsrc.php/v2/y6/r/luizkbRWOQS.js could save 24.2KiB (67% reduction).
Compressing https://static.xx.fbcdn.net/rsrc.php/v2/yI/r/oDzewPwhRt1.js could save 21.7KiB (74% reduction).
Compressing https://static.xx.fbcdn.net/rsrc.php/v2/yP/r/gcdIMTVPpBq.css could save 17.3KiB (77% reduction).
Compressing https://static.xx.fbcdn.net/rsrc.php/v2/yf/r/nrh6Sehx1Iz.css could save 15.4KiB (73% reduction).
Compressing https://static.xx.fbcdn.net/rsrc.php/v2/yV/r/1pZAFn_KQPn.css could save 14.2KiB (74% reduction).
Compressing http://www.advancebestmaid.com.sg/ could save 12.7KiB (72% reduction).
Compressing https://static.xx.fbcdn.net/rsrc.php/v2/ya/r/acNHHHLf-Ph.js could save 11.3KiB (69% reduction).
Compressing https://static.xx.fbcdn.net/rsrc.php/v2/yR/r/qGNhIQHDeK2.js could save 9.3KiB (63% reduction).
Compressing https://static.xx.fbcdn.net/rsrc.php/v2/yr/r/V2fXuYrZ-4H.css could save 3.6KiB (71% reduction).
Compressing https://static.xx.fbcdn.net/rsrc.php/v2/yY/r/Uj-Y3GNRxq1.js could save 3.3KiB (59% reduction).
I already checked with my server to make sure that, GZIP is enabled. And I'm using Yoast SEO plugin to enable HTTP (gzip) compression on my site.
This is my .htaccess code:
<IfModule mod_deflate.c>
# Compress HTML, CSS, JavaScript, Text, XML and fonts
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
# Remove browser bugs (only needed for really old browsers)
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
</IfModule>
I cannot understand why the compression not working. Please help me guys.
URL: mysite

add these lines too
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_include mime ^text/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_include handler ^cgi-script$
</ifModule>

You cannot compress external (loaded from external domains) javascripts or css. Almost all those files are loaded from https://static.xx.fbcdn.net/. You have to complain about it to Facebook. It is their domain.

Related

Apache GZip not working text files and js files?

I am trying to add GZip compression using Apache mod_deflate module. All contents get compressed except text files(".txt"). Also facing issues when compressing HTML files and JS files.
For Example: Let's say a script file ("main.js") hosted on http://example.com
The contents of file:
In case 1:
// Contents of main.js
console.log("Hello World");
console.log("Hello World");
console.log("Hello World");
console.log("Hello World"); console.log("Hello World");
In case 2:
// Contents of main.js
Hello World! Hello World!
Hello World! Hello World! Hello World!
Hello World! Hello World! Hello World! Hello World!
Random Contents
In case 1, When I visit http://example.com/main.js, it shows content-encoding: gzip.
In case 2, When I visit http://example.com/main.js, it doesn't show any content-encoding: gzip header.
So the GZip only works in Case 1 for .js files.
GZip not working on text files(.txt extension) and not showing any content-encoding: gzip header.
// .htaccess code
<IfModule mod_deflate.c>
<IfModule mod_mime.c>
AddType text/plain .txt
</IfModule>
SetOutputFilter DEFLATE
</IfModule>
My software list
Apache Version - 2.4.39
PHP Version - 7.3
OS - Windows 10
Software - Wamp 64Bit
If you add default mod_deflate and mod_gzip conf in .htaccess file some changes?
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
# Remove browser bugs (only needed for really old browsers)
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
</IfModule>
<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_include mime ^text/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_include handler ^cgi-script$
</IfModule>

Optimization of magento website

I am using magento 1.8.1 and it is very slow. I want to optimize this, for that I am using some free module for HTML, CSS and JS minification but its doesn't work.After using that it create lots of error. I've referred website such like after merge JS, the custom module in front-end is stop working. I've checked lots of tutorial also for gzip compression and enabling Mod_deflect, I've followed all the step like put some code in .htaccess page like
<IfModule mod_deflate.c>
# Compress HTML, CSS, JavaScript, Text, XML and fonts
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
# Remove browser bugs (only needed for really old browsers)
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
</IfModule>
But that also didn't work.
this is my website: Link
Please help me into this.
Magento has the option to merge css and js files which works for me. I minimise the css and js files I use but I DON'T minimise the standard Magento files (epsecially prototype. I've read that this can break things).
As for compression, it's possible that you can't use the standard htaccess approach. See Compressing js & css files where mod deflate not available for a way around it.
Try to merge CSS and JS byon the admin panel System > Configuration > Developer (Be careful with the JS, the site stop working right in my case).
The thing that change everything for me it's changing the cache module. Magento use a cache module witch use the Zend_Cache library and create a huge numbers of files that makes the site terrible slow. You can easy replace it with this:
Cm_Cache_Backend_File
or even better, magento is prepeared to work with Redis. With this feature the cache goes to RAM instead the File System.
Good luck!

gzip compression not working on xampp

for some reason the gzip is not working
my gzip compression script
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
i am using:----
XAMPP server.last time updated:2 min before the time of this question
NOTE:ALL FILES ARE A .PHP FILE,AND .HTACCESS FILES ARE IN ROOT FOLDER
HOW I FOUND OUT THAT IT IS NOT BEING GZIPPED:BY RUNNING AUDIT IN GOOGLE CHROME (DEVELOPER TOOLS)
Uncomment this line on httpd.conf
LoadModule deflate_module modules/mod_deflate.so
LoadModule filter_module modules/mod_filter.so
I'm betting your xampp install is not very old and you're probably using a recent version of Apache. So you should use mod_deflate.
mod_gzip is for Apache 1.x and mod_deflate is Apache 2.x
You can try this and customize as needed.
<IfModule mod_deflate.c>
<FilesMatch "\.(html|txt|css|js|php|pl)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
Or you can try it this way as well.
# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE image/jpeg
AddOutputFilterByType DEFLATE image/png
AddOutputFilterByType DEFLATE image/gif
#Custom Setting End.
You may also have to enable it in the Apache config. So you would uncomment this line and restart Apache.
LoadModule deflate_module modules/mod_deflate.so
You can also see gzip info here.
http://developer.yahoo.com/performance/rules.html#gzip

Gzip compression in multiple files

I am using Vanilla 2 forum and i noticed that my host does not support gzip.
I also noticed that in the php info file gzip is enabled.
So what i am trying to do is to put this line of code:
ob_start("ob_gzhandler");
at the very first line after the php tags. But there are almost 1000 php files in the whole vanilla script. Is there a way to automate this?
Or is there another alternative to gzip my website?
Update:
My .htaccess file:
# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
# Or, compress certain file types by extension:
<files *.html>
SetOutputFilter DEFLATE
</files>
There's the auto_prepend_file directive, which lets you force a particular chunk of code to be prependted to every file. You could put the ob code into that file, point PHP's prepend at it, and boom, gz output on all the scripts.

Can I tell mod_deflate & PHP to skip compression on one directory only?

To compress all my web page, I use this .htaccess code. It uses Apache deflate module if possible, else apply the PHP ob_gzhandler compression.
Everything is working fine, but for specific reason, I don't want to apply the compression for the folder ./folderWithoutCompression.
Question : How can I add this exception in case of Apache deflate module is defined or not (PHP ob_gzhandler case) in my following script below?
<IfModule mod_deflate.c>
# force deflate for mangled headers
# developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping/
<IfModule mod_setenvif.c>
<IfModule mod_headers.c>
SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
</IfModule>
</IfModule>
# HTML, TXT, CSS, JavaScript, JSON, XML, HTC:
<IfModule filter_module>
FilterDeclare COMPRESS
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/html
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/css
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/plain
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/x-component
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/javascript
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/json
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/xhtml+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/rss+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/atom+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/vnd.ms-fontobject
FilterProvider COMPRESS DEFLATE resp=Content-Type $image/svg+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/x-font-ttf
FilterProvider COMPRESS DEFLATE resp=Content-Type $font/opentype
FilterChain COMPRESS
FilterProtocol COMPRESS DEFLATE change=yes;byteranges=no
</IfModule>
<IfModule !mod_filter.c>
# Legacy versions of Apache
AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
AddOutputFilterByType DEFLATE application/xhtml+xml application/rss+xml
AddOutputFilterByType DEFLATE application/atom+xml
AddOutputFilterByType DEFLATE image/svg+xml application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font-ttf font/opentype
</IfModule>
</IfModule>
<IfModule !mod_deflate.c>
#Apache deflate module is not defined, active the page compression through PHP ob_gzhandler
php_flag output_buffering On
php_value output_handler ob_gzhandler
</IfModule>
EDIT
As workaround, I am using a custom content-type for all files present in my folderWithoutCompression folder.
I am sure that it is possible to exclude some directory using <Location>, <LocationMatch>, <DirectoryMatch> or <Directory>, but when I try to deal with, I always got an Apache error 500
I finally find the answer here :
How to disable mod_deflate in apache2?
Thanks #Gumbo
# for URL paths that begin with "/foo/bar/"
SetEnvIf Request_URI ^/foo/bar/ no-gzip=1
# for files that end with ".py"
<FilesMatch \.py$>
SetEnv no-gzip 1
</FilesMatch>

Categories