Saturday, April 6, 2013

Prepare site for upload to production server

When you prepare your web site for production you need to enable compression in order to save bandwidth and get higher rank in Google SERP. You can check the results of your compression using free tools like Google Web Master Tools
just click on Lab -> Site Performance link.

For quick test you can use gzip test but on a single file at a time. WordPress has a lot of plugins for caching and compression.

You need to minify and combine your JavaScript and CSS files. If you use WordPress or some other CMS then you have various plugins to do that. If not you can minify them on-line with this popular minifier and save on your server.

Outsourcing comment to sites like Disqus and IntenseDebate is a good idea since they take care of things like login width Facebook / Twitter account, spam and most of files is downloaded from their servers.

Another way to preserve bandwidth is to load jQuery, jQuery UI and other popular JavaScript frameworks from Google's CDN. At http://code.google.com/apis/ajaxlibs/ you can find instruction how to do that.

Here is quick solution for jQuery that loads minified files:

<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>

If you have control over .htaccess file and Apache modules you can enable compression like this:

<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>

If you have zlib copmression enabled put the following source code at the beginning of your scripts:

<?php
ini_set( 'zlib.output_compression_level', 3 );
ob_start( "ob_gzhandler" );

Keep in mind that this solution compresses only HTML code not JavaScript, CSS and image files. So if you use WordPress chose one of many compression plugins.

Running monthly daily and other maintenance tasks such as deleting revision of your posts on blog should be done with cron jobs. To run a cron in cPanel open Cron Page and type:

php /home/cPanel_user_name/public_html/folder/script_name.php

script_name contains PHP script you want to execute.

One more tip: add flush function between </head> and <body> tag to speed up page loading.

</head>
<?php flush(); ?>
<body>

Keep in mind that using flush() could conflict with some compression methods and create problems.

No comments:

Post a Comment