قالب وردپرس درنا توس
Home / Tips and Tricks / Speeding up a slow website – CloudSavvy IT

Speeding up a slow website – CloudSavvy IT



  Web Browser Quick Test
Lineicons Freebird / Shutterstock

People are more diaper than you might think ̵

1; according to Google research, 53% of mobile users leave your site if it takes more than three seconds to load. You want your site to quickly improve your conversion rate and search engine rankings.

How to Check Your Website Speed ​​

Perhaps the most important measure of your site's speed is Google's PageSpeed ​​Insights test. Since Google is the arbiter of how well your site performs in its rankings, you want to please them as much as possible. A good score on the PageSpeed ​​Insights test directly affects your SEO. Simply enter the URL of your site and click & # 39; Analyze & # 39; to view your results.

PageSpeed ​​Insights gives a very thorough overview of what's currently wrong with your site. You have to go through them as a checklist until your score is much higher. Google maintains a list of in-depth recommendations for you to check.

To investigate exactly how your page loads by your browser, you can access the Chrome developer tools (right click> Inspect or from the settings menu). Here are two useful tabs: Network and Performance.

The Network tab shows an easy-to-use timeline of requests to your site, how big the response was, and how long it took. The Performance tab provides a much more detailed view of everything that is happening to your website:

From here you can diagnose almost any performance issue on your site, including non-optimized JavaScript code, again generated, and recalculations of styles.

Install Google's PageSpeed ​​module

The PageSpeed ​​extension for Apache and Nginx performs many automations for general optimization of your site, such as shrinking and compressing your HTML, compressing your images, combining multiple JS and CSS files in one download, and generally just reduces the bulk. It is not a collection point, but it is an easy solution to common problems.

Reduce the size of your website

By reducing the size of your website, the download time is immediately reduced. While desktop users may still download your site fairly quickly, people with a mobile connection may freeze your website if it is not optimized.

Compressing images and loading lazily

The first way to reduce the size of images is to handle images. Images (and other media) are often a major culprit of slow sites. If you don't check the size of your images, there is a chance that many of them will be several megabytes in size, which can take a long time to load slow connections.

You need to check the size of your images (which you can do on the Network tab in the Chrome Dev Console) and make sure none of them are within the megabyte range. Most images on this site are approximately 100 Kb in size.

If you have large images, you want to compress them. There are many online tools that can do this, or you can manually re-export them from Photoshop, or you can convert an entire folder from the command line with ImageMagick:

  for f in * .jpg; convert quality 70 $ f $ f; done 

This compresses any .jpg file to 70% quality, which should save a lot of space while being almost indistinguishable from higher quality settings.

Images are not blocked, meaning the rest of the site loads while you wait for your images. But you don't have to load them all at once, especially when more important things need to be downloaded before the images.

You can fix this by loading lazy your images. This technique slows down the loading of your images until they are needed, and instead displays a placeholder (which prevents your content from shifting when the real images are loaded). These placeholders are often made to be the "dominant color" or a smaller, blurry image that loads faster, which minimizes the shocking effect of loading.

You can lazily load images with a WordPress plugin, with some simple JavaScript, or with a JS library

Shrink and zip JavaScript files

You should try not to have too much JavaScript, but if you have to reduce the size of the script files. The main method of this is to shrink and compress them.

Minifying is a technique in which all unnecessary part of your code is removed and replaced by fewer characters. White spaces, new lines, tabs – all gone. Function and variable names are replaced with single characters. Granted, it looks awful:

But it does reduce the file size and no one will admire it anyway. You can shrink during implementation, so don't worry, you don't have to work on code like this.

Gzipping is another step that uses actual text compression, which can save even more space. There is a slight CPU overhead when the browser has to decrypt the file, but the size savings justify these costs. Browsers compatible with compressed files send an Accept-Encoding: gzip header in their resource requests, letting the server know that it can offer the compressed versions.

Both steps speed up the loading of your JavaScript resources. In fact, minified JavaScript is actually parsed and executed a little faster, so it's better in that regard too.

Get rid of unnecessary bulk

The last step to improve site performance is simply to remove the things you don't need. If you're loading a lot of JavaScript libraries, consider coding a simpler solution without the need for an external source. jQuery is an example of this; it's great to have and makes working with JS much easier, but it blocks the display and is often more clunky than vanilla JS. If you go for "ASAP", don't use jQuery.

The same goes for WordPress plugins and widgets; if they are not completely necessary, they can weigh down your site. Try to streamline your site as much as possible.

Avoid Rendering Block Resources

Block Certain Resources on Your Site Rendering which means that the page will not load at all until those resources are downloaded. Obviously, your HTML blocks the view, but your JavaScript usually is. This means that a user will submit a request to your site, wait to download your HTML, see that they need an extra JS file, and then wait to download that file as well. This is a major problem as it directly extends your loading times.

Here are a few solutions for:

  • Inline JavaScript. Instead of linking to an external source, paste the entire contents of the JavaScript file you are trying to load into a

The type of CDN you want to use is an origin pull CDN, such as CloudFlare or Fastly, which caches your site at any point of presence, speeding up travel time and consuming your web server. CDNs can even shrink your images to the edge because they can detect the device very quickly and offer smaller versions to mobile users.

You can also use an original push CDN to supply static resources to more people than a traditional monolithic web server could manage. This is often used for video hosting, but can also display images and files.

An origin pull CDN also improves latency by reducing the trips your web server makes to your database every time dynamic content is requested. WordPress and PHP are the main culprits of this; every time a message is requested, the PHP script retrieves the page content from the database. This is not necessary at all to do several times per second. Caching solves this problem by storing the "results" of a request for about a minute, which means your database is bugged much less often. If you don't have a CDN, you can still implement WordPress caching with a plugin like W3 Total Cache.

Using Browser Caching

Browsers can cache content so that future visits are faster. This has no effect on the loading of the first page, so it is only really useful for sites that have often had multiple visits per user in a short time (think of daily news, social media, etc.). However, this also applies to general resources such as your logo, which appear on every page. You want to cache it so that when a user clicks on your site, they don't have to waste time reloading stuff it already has.

This is done with the header-control header. You can use a CDN to get more detailed control over your caching rules, but operating them from the web server should work just as well.

In nginx, the max-age part of the cache-control header was set using the expires directive. For example, if you want to cache all images, CSS and JavaScript files for a year, you can use:

  location ~ * . (Jpg | jpeg | png | gif | ico | css | js) $ {
expires 365d;
} 

The problem with caching this way is that if you want to make changes to cached files, these changes will not be passed on to clients until they expire, which should ideally be long. The solution to this is to use version filenames and change versions if you want to make changes:

   

Or even:

   

Anyway, you have to consider what you are caching and for how long. You shouldn't really use the browser cache for things like a static home page; if you want to cache your HTML content, you must use a full site CDN to implement server-side caching.

In addition, you can set the cache-control mode with add_header :

  location ~ * . (Jpg | jpeg | png | gif | ico | css | js) $ {
expires 365d;
add_header Cache-Control "public";
} 

"Public" allows anything to cache it, including a CDN. Do not use this for anything that requires authentication. & # 39; Private & # 39; stores something in a user's browser, but not on CDNs. "No-store" will completely disable caching.


Source link