Accelerating the website can often be a demanding job requiring detailed planning, knowledge of different areas, with a focus on testing and evaluation. Often, there are several teams working on this segment: web developers, system administrators, network experts, and other professionals. In this article, we will show you how to speed up a website on a CentOS 7 server.
Why is the website speed so important?
The answer is simple – the download speed affects the ranking of your website on search engines. The website’s download speed is included in the search engine ranking factors, and therefore this is an important SEO factor. Slow websites negatively affect the conversion rates that are crucial to the success of every online business.
Use fast and reliable hosting
It’s obvious that you need to use reliable web hosting if you want your website to be loaded fast.
Enable gzip compression
Images are mostly compressed, but textual content leaves plenty of room for “zipping”. The web server can be configured to send compressed content to all web browsers that can accept it. This makes sense to do with all the textual content, such as HTML, JavaScript, CSS, text, and XML files.
All new web browsers allow you to read HTML, CSS and Javascript files in compressed form.
In order to enable GZIP compression, it is necessary to configure the web server so that it compresses all files before sending it compressed in GZIP format. Specific configuration commands depend on the type of the server. On CentOS servers with Apache, the simplest solution is to modify the .htaccess file located in the root directory of your website.
vi .htaccess
If you do not have this file, you need to create it yourself and enter the following code into it:
<IfModule mod_deflate.c> # Enable HTML, CSS, JavaScript, Text, XML and font compression 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>
Configure web browser caching
An important setting is “expiration date”, that determines the “shelf life” of a file on the server. If the “expiration date” is not set for the files, they will be loaded directly from the server at each request by the visitor. Otherwise, the web browser will load the same file on the user’s computer, not the server, if it has to load the file on the user’s computer again. The result is clear, saving in loading time and resources is enormous. This setting is recommended mostly for static content on the site, which is rarely being changed. These can be images, Javascript, and even CSS files.
In order to allow caching of such files, it is necessary to re-edit the .htaccess file in the root directory of the website, i.e. add the following code to it:
<ifModule mod_headers.c> <filesMatch "\\.(ico|pdf|flv|jpg|jpeg|png|gif|swf)$"> Header set Cache-Control "max-age=2592000, public" </filesMatch> <filesMatch "\\.(css)$"> Header set Cache-Control "max-age=2592000, public" </filesMatch> <filesMatch "\\.(js)$"> Header set Cache-Control "max-age=216000, private" </filesMatch> <filesMatch "\\.(xml|txt)$"> Header set Cache-Control "max-age=216000, public, must-revalidate" </filesMatch> <filesMatch "\\.(html|htm|php)$"> Header set Cache-Control "max-age=1, private, must-revalidate" </filesMatch> </ifModule> <IfModule mod_expires.c> ExpiresActive On ExpiresByType image/jpg "access 1 year" ExpiresByType image/jpeg "access 1 year" ExpiresByType image/gif "access 1 year" ExpiresByType image/png "access 1 year" ExpiresByType text/css "access 1 month" ExpiresByType text/x-javascript "access 1 month" ExpiresByType image/x-icon "access 1 year" ExpiresDefault "access plus 1 year" ExpiresByType application/vnd.ms-fontobject "access plus 1 month" ExpiresByType application/x-font-ttf "access plus 1 month" ExpiresByType application/x-font-woff "access plus 1 month" ExpiresByType font/opentype "access plus 1 month" ExpiresByType image/svg+xml "access plus 1 month" </IfModule>
By using these simple .htaccess rules for caching, you can dramatically improve the speed of the website.
Use a CDN
Content Delivery Network (CDN) is a collection of web servers distributed across multiple locations in order to provide more efficient content delivery to users. Using this solution can help your website get faster by 20% or more.
Reduce HTTP requests
In order to reduce page loading time, you also need to reduce HTTP requests. This means that you need to:
- reduce the number of JavaScript files or try combining many JavaScript files into one bigger file,
- reduce the number of CSS files or try combining many CSS files into one bigger file,
- reduce the number of images.
That’s it, your website should be faster now. If your website based on WordPress, you can use plugins to do some of the steps mentioned above.
If you use one of our premium server management services our expert system engineers can speed up and optimize your website for blazing fast speeds. They are available 24×7 and will take care of your request immediately.
PS. If you liked this post on how to speed up your website on CentOS 7, please share it with your friends on the social networks using the buttons below or simply leave a reply in the comments sections. Thanks.