I have this in my .htaccess:
# Insert filter on all content
SetOutputFilter DEFLATE
# Insert filter on selected content types only
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
And all my static content returns Content-Encoding: gzip. But my PHP-generated pages doesn't and GTmetrix site says that I need to compress this content (my web-pages). How to enable gzip for PHP -generated pages?
I have the same .htaccess settings in another project and web-pages compression works on it.
My site uses Magento 2 engine.
The problem was in shared hosting settings. I contacted the support and they enabled compression for pages.
Related
How do you get gzip to work on a Wordpress site setup in MAMP?
I've got gulp creating the file /dist/css/main.css.gz and have added it to the header PHP file of my wordpress site.
I then lose all of my styling. I'm assuming this is because I haven't enabled it in my .htaccess? So I found the following code to add to my .htaccess:
<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>
And it still does not work.
I'm not sure why you'd want to store your files as gzip archives, but this is not the way to do it. AddOutputFilterByType DEFLATE text/css will compress the file before sending it. To decompress an existing file, something like this will work (tested with 2.2):
<Directory />
AddOutputFilter INFLATE gz
RemoveType .gz
AddType text/css .css.gz
</Directory>
Test output:
$ echo "body {color:black; background:white;}" > foo.css
$ gzip foo.css
$ curl http://localhost/foo.css.gz
body {color:black; background:white;}
$ curl -I http://localhost/foo.css.gz
HTTP/1.1 200 OK
Date: Fri, 07 Jul 2017 23:01:22 GMT
Server: Apache/2.2.15 (Scientific Linux)
Last-Modified: Fri, 07 Jul 2017 22:59:22 GMT
Content-Length: 38
Content-Type: text/css
$
Of course, this interferes with your ability to serve actual gzip files, and you'll need to manually specify MIME types for each compressed file.
Also, if you're controlling the server you should not be using .htaccess files. They're slow and present a security risk. Put this in the server configuration!
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!
Here In a Wordpress site, I have enabled gzip compression at .htaccess. I have checked gzip compression and Content-Encoding appears correctly here.
But when checking compression at Chrome's developer tool, it doesn't show Content-Encoding on Response section:
Here are the .htaccess compression statements:
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
AddType x-font/otf .otf
AddType x-font/ttf .ttf
AddType x-font/eot .eot
AddType x-font/woff .woff
AddType image/x-icon .ico
AddType image/png .png
Why Chrome won't show gzip information?
It seems that Google Chrome, as Mozilla Firefox already decodes content. But there is a difference between them.
In Request Headers the extra field Accept-Encoding: "gzip, deflate" shows up but in Response Headers there is no Content-Encoding: gzip
Using Fiddler is possible to click in Transformer button (from Response Headers section) and choose to encode content. After that click in Raw button to check if content-encoding is being used.
So Fiddler is nicer to check for response headers.
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.
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