What is file minification? It is nothing more than removing unnecessary spaces, enters, tabs and comments from HTML, JavaScript and CSS files, which are irrelevant to the code interpreter and unnecessarily increase the size of files. Minified files are lighter and as a result the page loads faster.
CSS code with unnecessary characters
Code before minification
code after minification - removing unnecessary characters
Code after minification
How to enable file minification? We can write our own script that will remove unnecessary characters from files. In the case of websites with the WordPress engine, it is worth using the WP Fastest Cache plugin. The CloudFlare service also minifies files, more about which later in the article.
5. Using browser cache
What is browser cache? Also known as browser caching - This is a place on the user's device where static elements of our website can be saved (for a specified period of time). We are talking about storing data on mobile devices, tablets, computers, etc. As a result, when we go to another subpage or visit the website after a few days, some resources are loaded directly from the device, which significantly speeds up the loading of the page.
How to enable browser cache? We can do this in several ways, for example by changing the settings in the server administration panel. The most popular option is to set the browser cache in the .htaccess file, which is shown below:
If you are using WordPress, you can install the WP Fastest Cache plugin and solve the problem.
WP Fastest Cache - wodrpress plugin
WP Fastest Cache plugin setup
6. Code reduction and optimization
Another factor that does not optimally affect the speed of loading a website is excessive code. This is especially true for PHP and JS scripts that are not used, but are nevertheless loaded and processed by the server / browser.
On WordPress and other popular CMS systems , such a problem is most often generated by an excessive number of installed plugins. Especially when we use multifunctional plugins, and we only use selected functions - despite this, the entire code of the plugin and other functions is loaded and executed.
The problem of code optimization is complex and also concerns skype database the duplication of unnecessary tags and styles, e.g. each paragraph in the code has an identical inline style, as a result it is duplicated dozens of times.
Also pay attention to universal website templates - their code is created for a wide group, which is why it is not optimal. In such a case, there will always be a lot of unused code. Our programmers recommend creating a new and lighter template based on the appearance of the previous one. Visually, the page will be practically the same - but the performance and loading time will improve significantly.
How to limit and optimize the code? First of all, avoid installing many plugins. Install only those that you actually use and are necessary for the functioning of the site. It often happens that the functionality of the plugin is unnecessary and you can easily achieve the same effect without it, e.g. creating redirects, optimizing graphics, implementing analytical tags can be done by yourself, it only requires a little technical knowledge.
Analyze the internal scripts you use and those loaded from external sources. Get rid of unnecessary ones or modify them so that they load only on specific pages - not every page.
When entering content onto a page, verify that the pasted content does not contain unnecessary styles from the document from which it was copied.
If we use external resources to properly load our page, it is worth using the rel="preconnect" attribute in the tag.
How does it work? We tell the browser to connect to another domain as soon as possible. This happens before the actual query for the resource, which means that when such a query occurs, the resource is downloaded immediately. The attribute should be used with caution, because overusing it can be counterproductive. You can find more about using the attribute at this link .
If you're building a website from scratch, check out how to create and optimize a website template .
7. Avoiding multiple redirects
Redirect chains slightly increase the time it takes for the target page to load. This is because the server, when asked for a URL, usually returns the address to which the redirect points , and then the browser must send another request, this time to the address received in response. It is good practice to avoid redirects, e.g. from page A to page B, and from page B to page C. This will speed up the load speed of the target page.
Minification of JavaScript, CSS and HTML files
-
- Posts: 30
- Joined: Mon Dec 09, 2024 3:42 am