Website speed is critical to build a business success. But sometimes, we just have limited budget for our small website. We are unable to purchase expensive speed up service like CDN. When this happens, how to make website download faster?
Choose Nearby web hosting
All website data transferring between web hosting and readers’ client need passing through network cable and transit in network nodes. The longer the distance, the longer the cable and the more nodes. Data transit in cable and nodes has a fixed speed. Choose a web hosting nearby the targeted reader will definitely decrease transmit time. This is the basic theory for CDN. That means, if you are running local business, best idea is the web hosting in your area with comparatively cheap price.
Enable Gzip compression
Gzip compression works in the same way as compressing file on PCs. Once enabled, Gzip automatically compresses website’s files in Gzip format before sending them for download. This method of transmitting content from the server to the browser is far more efficient and saves a lot of time. According to Yahoo, this can reduce download time by about 70%.
Enable the deflate module
a2enmod deflate
Create Gzip configuration
Add the following code to Apache configuration or the .htaccess file (found in the root directory on your server):
<IfModule mod_deflate.c> <IfModule mod_filter.c> # these are known to be safe with MSIE 6 AddOutputFilterByType DEFLATE text/html text/plain text/xml # everything else may cause problems with MSIE 6 AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE application/x-javascript applicat$ AddOutputFilterByType DEFLATE application/rss+xml AddOutputFilterByType DEFLATE application/xml </IfModule> </IfModule>
Enable keep-alive connection
Keep alive is a method to enable multiple HTTP requests in the same tcp connection. When keep alive not enabled, each HTTP request set a tcp connection. Client browser sent HTTP request for each document which takes significantly longer to display the webpage. The keep alive enables grab more than just one file at a time.
For Apache configuration:
Find KeepAlive and make it
KeepAlive On
For .htaccess configuration:
<ifModule mod_headers.c> Header set Connection keep-alive </ifModule>
Enable browser caching
Browser caching is a tricky issue. Leverage browser caching makes browser reading files from cache other than download from the web hosting. Cache files with lower renewal rate ensure returning visiters opening website faster. Mostly, website icon, pictures, css, javascript remains the same without update in short period. Enable cache from server end by using the following steps.
Enable expire module
In a LAMP stack, type this snippet:
a2enmod expire
Browser caching configuration
Add the following lines to Apache configuration or the .htaccess file. It specify the file type to cache and its expire time. The A86400 state the file cache expire after 86400 second.
<IfModule mod_expires.c> ExpiresActive on ExpiresDefault A86400 ExpiresByType image/x-icon A7776000 ExpiresByType application/x-javascript A604800 ExpiresByType application/javascript A604800 ExpiresByType text/css A604800 ExpiresByType image/gif A2592000 ExpiresByType image/png A2592000 ExpiresByType image/jpeg A2592000 ExpiresByType text/plain A86400 ExpiresByType application/x-shockwave-flash A2592000 ExpiresByType video/x-flv A2592000 ExpiresByType application/pdf A2592000 ExpiresByType text/html A3600 ExpiresByType application/x-font-woffl A7776000 ExpiresByType application/vnd.ms-fontobject A7776000 ExpiresByType image/svg+xml A7776000 </IfModule>
Use PHP OPcache
OPcache is a build in module in PHP from PHP5.5. It is formerly the Zend Optimizer. It improves PHP performance by storing precompiled script bytecode in the shared memory. Enable OPcache module will speed up your PHP application.
Open the php.ini file and ensure the configuration as follow:
;enable the Zend opcache opcache.enable=1 ;maximum memory opcache can use. (in megabytes) opcache.memory_consumption=256 ;The maximum number of keys (scripts) in the OPcache hash table. opcache.max_accelerated_files=5000 ;How often (in seconds) to check file timestamps for changes to the shared memory storage allocation. opcache.revalidate_fre=240
Use Google Apache module mod_pagespeed
The mod_pagespeed is a open source Apache module from Google. It is aimed to speed up website and save bandwidth. Use the following command to install the mod_pagespeed.
wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-beta_current_amd64.deb sudo dpkg -i mod-pagespeed-*.deb sudo apt-get -f install
The default mod_pagespeed configuration has enabled many safe functions like combine CSS, compressor CSS, etc. For more information, check https://developers.google.com/speed/pagespeed/module/
After these steps, don’t forget to restart Apache server.
service restart apache2
Use Google Pagespeed check you website speed for something more can be improved: https://developers.google.com/speed/pagespeed/insights/
For a shared hosting, the same method can be used. But you may need to contact hosting administrator to make sure you have the authority.