gzip compression not working on xampp - php

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

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>

.htaccess Internal Server Error while enabling Gzip

I am trying to enable Gzip compression on my wordpress website. But when i try to add the compression code, i am getting the following error.
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at webmaster#coachhire4u.com to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
Apache/2.4.18 (Unix) OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4 PHP/5.5.31 Server at www.coachhire4u.com Port 80
My .htaccess file,
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/customer/quote/payment/
RewriteRule (\d+)/(\d+) http://www.coachhire4u.com/?c4u_payment_id=$1
[L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Compression code
# Compress HTML File, CSS File, JavaScript File, Text File, XML File and Fonts
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/x-httpd-php
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 font/otf
AddOutputFilterByType DEFLATE font/ttf
Please help me to resolve this issue. I know there are similar posts, but none of them seem to help
thanks
There are different approchaes of achieving compression. Which one to use depends on the capabilities/setup of your server. It's always a good idea to surround blocks with <ifModule></ifModule> where possible, in order to prevent 500 status errors.
There's a good chance that the following will work on your local machine as well as on your server. However, with the sparse informatione provided, it's not possible to give a definite answer. But I'll gladly update this answer if this does not work and you can provide further debugging information.
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|json|php|pl|svg)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_include mime ^application/json.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
<ifModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/xml text/css text/plain
AddOutputFilterByType DEFLATE image/svg+xml application/xhtml+xml application/xml
AddOutputFilterByType DEFLATE application/rdf+xml application/rss+xml application/atom+xml
AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript application/json
AddOutputFilterByType DEFLATE application/x-font-ttf application/x-font-otf
AddOutputFilterByType DEFLATE font/truetype font/opentype
</ifModule>
AddType image/svg+xml svg svgz
AddEncoding gzip svgz
It might be a bit late, but I hope this helps.
I fixed my error by going to httpd.conf for my Apache server configuration and uncommenting the lines containing mod_filter.so and mod_deflate.so.

GZIP Compression Not Working For Wordpress Site

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.

500 error when compressing files with .htaccess

I'm trying to compress files with .htaccess but I'm getting a 500 internal error,
This is the code I'm trying to use.
# JavaScript compression htaccess ruleset
AddHandler application/x-httpd-php .js
php_value auto_prepend_file gzip-js.php
php_flag zlib.output_compression On
I've also tried this but getting the same error,
<files *.html>
SetOutputFilter DEFLATE
</files>
Any suggestions why?
Do you have mod_deflate installed? Try this instead and see if your error goes away.
<ifModule mod_deflate.c>
<Files *.html>
SetOutputFilter DEFLATE
</Files>
</ifModule>
If this resolves the 500 error, then you probably don't have mod_deflate installed. You can test it by visiting HTTP Compression Test.
If you have access, you may be able to enable it by uncommenting the following lines in your httpd.conf file.
LoadModule filter_module modules/mod_filter.so
LoadModule deflate_module modules/mod_deflate.so
Then you will need to add an output type for each file type you wish to compress.
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
As mentioned in the comments, AddOutputFilterByType depends on mod_filter. If you still get a 500 error you should check that this module is loaded too.
You can read more here: Use mod_deflate to Compress Web Content delivered by Apache
I can't find any documentation that suggests whether Siteground supports mod_deflate or not. Their KB suggests using gZip from PHP.
How to enable gZIP compression for your pages?
How to compress my CSS with gZIP?
After spending hours of search I found this article, thought someone else might find it helpful,
Enjoy.
## DEFLATE ##
#mod_filter.so and mod_deflate.so
should be ON !!!!
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
</ifmodule>
This worked fine for me (paste in .htaccess):
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

How do I site optimization php files with gzip compression using .htaccess or php.ini?

I'm using .htaccess provided by http://html5boilerplate.com/ which is correctly compressing the .html, .css, & .js files but I have not been able to get the .php files to compress unless I add <?php if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start(); ?> to the top of the page. The last thing I want to do is add that line to a hundred plus pages.
I've been using the following two sites to verify the gzip compression:
http://www.whatsmyip.org/http-compression-test/
http://www.gidnetwork.com/tools/gzip-test.php
The following suggestions have not worked either:
Gzip compression through .htaccess not working
How do you use gzip in .htaccess or php.ini?
I've also tried the following (http://perishablepress.com/fast-effective-php-compression/):
<?php // placed in a gzip_start.php file
ob_start("ob_gzhandler");
?>
<?php // placed in a gzip_stop.php file
ob_flush();
?>
# Placed in the .htaccess filew
# dual file includes for PHP compression
php_value auto_prepend_file /specify/full/path/to/gzip_start.php
php_value auto_append_file /specify/full/path/to/gzip_stop.php
Here's the Gzip section of my .htaccess file:
# ----------------------------------------------------------------------
# Gzip compression
# ----------------------------------------------------------------------
<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(gzip|deflate)?|X{4,13}|~{4,13}|-{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|css|javascript|plain|x(ml|-component))/
FilterProvider COMPRESS DEFLATE resp=Content-Type /application/(javascript|json|xml|x-javascript)/
FilterChain COMPRESS
FilterProtocol COMPRESS change=yes;byteranges=no
</IfModule>
<IfModule !mod_filter.c>
# Legacy versions of Apache
AddOutputFilterByType DEFLATE text/text text/html text/plain text/css application/json
AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript
AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
</IfModule>
# Webfonts and SVG:
<FilesMatch "\.(ttf|otf|eot|svg|php)$" >
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
Edit Your .htaccess File like This
# 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:
&ltfiles *.html &gt
SetOutputFilter DEFLATE
&lt/files&gt
&ltfiles *.css&gt
SetOutputFilter DEFLATE
&lt/files&gt
&ltfiles *.js &gt
SetOutputFilter DEFLATE
&lt/files&gt
&ltfiles *.img &gt
SetOutputFilter DEFLATE
&lt/files&gt
If you have views with .php extension. You will have to add this to .htaccess file
<files *.php >
SetOutputFilter DEFLATE
</files>

Categories