Mobile app version of vmapp.org
Login or Join
Nimeshi995

: How do I enable compression to reduce the file transfer size on GoDaddy? I have hosted one of my website on godaddy.com. How do I enable compression to reduce the file transfer size? I need

@Nimeshi995

Posted in: #Compression #Css #Godaddy #Htaccess #Javascript

I have hosted one of my website on godaddy.com. How do I enable compression to reduce the file transfer size? I need to compress the .css and .js files. I tried the following but it doesn't work :

SetOutputFilter DEFLATE Header append Vary User-Agent

10.03% popularity Vote Up Vote Down


Login to follow query

More posts by @Nimeshi995

3 Comments

Sorted by latest first Latest Oldest Best

 

@Hamaas447

You could try what Godaddy recommonds on their site: Enabling mod_Deflate with Your Hosting Account. Add the following to your .htaccess file

AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript

10% popularity Vote Up Vote Down


 

@Annie201

Considering you have go-daddy, you might not have decent apache access. Use PHP and use the following template.

<?php
$compression_level=2; //any number from 1 to 9 depending on how much compression
ob_start();
// INSERT YOUR OUTPUT CODE HERE
$data=ob_get_contents();
ob_end_clean();
if (strpos(strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'gzip') !== false){
$data=gzencode($data,$compression_level);
header("content-encoding: gzip",true);
}
echo $data;
?>


What will happen here is a buffer is created which holds all output. After that, the buffer is stored as a variable. Then it checks to see if the client can support gzip decompression and if it does, then compress the code and result is in compressed format and send the gzip header along with the compressed data back to the client.

This code also returns normal uncompressed output for those with browsers that can't support gzip encoding.

Once that is done, you can either make reference to the PHP file directly in the HTML code, like this for example:

<link rel="stylesheet" href="http://www.whatever.com/css/css.php">


Or if you want to make the filename look pretty, look up the RewriteRule command for mod_rewrite. There's lots of examples on the net for that.

10% popularity Vote Up Vote Down


 

@Phylliss660

By compressing .js and .css, do you mean to minfy them or gzip compression. If you need to minify, just use css minfier or JS minifier.

And if you are asking about gzip compression, it is also too easier. Just create an .htaccess file in your ftp root (only if it doesn't exist), and paste the below code to it,

<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>

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme