A fast and responsive online store is critical for providing a good user experience, boosting conversions, and improving SEO rankings. Studies show that even minor delays can cause customers to abandon their shopping carts. With page load times directly impacting your bottom line, optimizing your Shopify store's speed should be a top priority.
While there are basic speed optimization techniques like compressing images, using a CDN, or optimizing code that any Shopify store owner should implement, more advanced merchants can take things a step further. This guide will cover advanced techniques to shave off precious seconds from your Shopify site's load time and dramatically improve performance.
We'll discuss advanced methods like minifying code, implementing asynchronous JavaScript, optimizing database queries, enabling gzip compression, lazy loading page elements, reducing redirects, advanced image optimization, and improving caching. Properly implementing even a few of these advanced tactics can significantly improve site speed and provide a smoother, faster experience for customers. Let's dive in and explore some advanced ways to give your Shopify store a performance boost.
Minify Code
Minifying code is the process of removing unnecessary characters from code without changing its functionality. This includes whitespace, comments, and other characters that aren't essential for the code to run properly. Minifying HTML, CSS, and JavaScript code can significantly reduce the overall file size that needs to be loaded by the browser.
For Shopify stores, minified code means faster page load speeds and better performance. Smaller file sizes allow pages to load more quickly, which improves user experience. Faster load times are also beneficial for SEO, as page speed is a factor in search engine rankings.
There are a few ways to minify code for a Shopify store:
Use the built-in "Minify HTML" setting under Shopify's Theme Settings. This will minify all the HTML code for the theme.
For CSS and JavaScript files, use a minification tool like Minifyre. This is an online tool where you can paste in CSS and JavaScript code and it will output a minified version.
Install a plugin like Minify JS, which will automatically minify JS code. There are similar plugins for minifying CSS as well.
Use a build tool like Webpack or Gulp to minify code during the build process. This approach takes more setup but allows automating code minification.
The key is to ensure all HTML, CSS and JS code going live is minified. Doing this for all sites files through the methods above can reduce the store's overall code footprint substantially. This means faster load times, happier customers, and potential SEO benefits.
Asynchronous JavaScript
Loading JavaScript synchronously can significantly slow down page load times. This is because the browser has to download, parse, and execute each JavaScript file one by one before rendering any content on the page.
Asynchronous JavaScript improves page load times by allowing the browser to continue rendering content while JavaScript files are downloading in the background. There are a couple ways to load JavaScript asynchronously:
Use the async and defer Attributes
The async and defer attributes allow you to load JavaScript asynchronously.
Adding async to a script tag downloads the file during HTML parsing and will pause HTML parsing to execute it when it's finished:
<script async src="script.js"></script>
The defer attribute also downloads the file during HTML parsing but will only execute after the page has finished parsing:
<script defer src="script.js"></script>
async is best for independent scripts that don't rely on other scripts, while defer is ideal when order matters.
Dynamically Create and Append Scripts
You can also load scripts dynamically by creating script tags dynamically and appending them to the document.
This allows you to load scripts on demand after the initial page load, avoiding blocking page rendering.
When used correctly, asynchronous JavaScript patterns can significantly improve page load times and performance on Shopify stores.
Image Optimization
Images can significantly slow down your site speed if they are not properly optimized. High-resolution product images especially can be several megabytes in size before optimization. The benefits of compressing your images include:
Faster page load times - Smaller image file sizes means the browser has less data to download. This directly speeds up how fast each page loads.
Reduced web hosting bandwidth usage - With smaller images, your store will use less of your monthly bandwidth allocation from your web host. This helps avoid costly overage fees.
Better user experience - Customers don't like waiting for huge images to load. Optimized images lead to happier customers.
There are two great free tools that can optimize your images - TinyPNG and Kraken. These use smart compression algorithms to reduce file sizes with minimal quality loss. For best results, you should optimize your images through one of these tools before uploading them to your Shopify store.
Alternatively, there are plugins like EWWW Image Optimizer and Imagify that will automatically compress images for you when they are uploaded. The plugin will seamlessly handle the optimization process in the background. Just install, activate, and let the plugin do its magic. This is the easiest "set and forget" option.
Properly compressing images is an easy win for dramatically improving your site speed. Take advantage of one of these tools or plugins to ensure your images are properly optimized. Your customers will thank you with faster load times, higher conversions, and more sales.
Caching
Caching is an effective way to speed up your Shopify store's performance. Caching stores a copy of your website files and images to reduce server requests and load times. There are several types of caching strategies that can help optimize your Shopify store speed:
Browser Caching
Browser caching allows webpages and assets to be temporarily stored on a visitor's browser so they don't have to be re-downloaded with every page request. This reduces bandwidth usage and speeds up load times. You can enable browser caching for your Shopify store by setting cache times in your .htaccess file or through caching plugins. Set longer expiry times for assets that do not change often.
Page Caching Plugins
Page caching plugins like Cachefly and WP Rocket generate static HTML copies of your pages and store them to serve to repeat visitors. This avoids resource-intensive backend processing and database queries on each request. Configure caching rules so dynamic pages are refreshed at set intervals while allowing maximum caching for static pages.
CDN Caching
Using a content delivery network (CDN) also facilitates caching. A CDN stores cached copies of your website resources on distributed servers around the world. Visitors are served content from edge servers closest to them, providing faster load times globally. Shopify has a built-in CDN, and you can further optimize it by purging cache when needed or selectively caching page elements.
Effective use of caching techniques like the above can significantly improve website performance and provide a smoother browsing experience for your customers. Combine multiple methods like browser, page, and CDN caching for maximum effect.
Reduce Redirects
Redirects can significantly slow down your site speed if not optimized properly. Every time a redirect happens, the browser has to make an additional request to locate the new URL, adding latency. Shopify sites often end up with redundant redirects due to changes in site structure, product URLs, and other factors over time.
There are a few ways to identify and reduce unnecessary redirects:
Use a site speed tool like PageSpeed Insights or WebPageTest and look at the waterfall chart. Any row with a status code of 301 or 302 is a redirect. Review these to see if they are needed.
Check your Shopify admin for old Pages and Blogs that may still be redirecting. Delete unused ones.
Install a redirect mapper plugin like Simple 301 Redirects. This will create a visual map of your redirects to easily identify chains and loops. Remove anything redundant.
When changing product handles or page URLs, use proper 301 redirects rather than deleting and recreating.
Consolidate multiple old URLs redirecting to one new URL using a single 301 redirect rule.
Avoid chaining more than 3-4 redirects.
With some cleanup of unnecessary redirects, you can shave precious seconds off your site speed. Properly mapped 301 redirects also preserve link equity when making changes. Invest time into reducing redirect bloat and your site performance will benefit.
Load Assets on Demand with Lazy Loading
Lazy loading is a technique to improve page load times by deferring the loading of non-essential assets until they are needed. Rather than loading all images, videos, iframes, and other media on page load, lazy loading only loads assets as they become visible in the viewport. This reduces the initial page payload and allows the page to render faster.
Lazy loading works by adding a loading="lazy" attribute to img, video, and iframe elements. This tells the browser to defer loading the asset until it near being scrolled into view. A placeholder or blurry image is shown until the full asset loads.
Some key benefits of lazy loading:
Faster initial page load time since fewer assets need to download right away
Reduces server load and bandwidth usage
Users only load images/media relevant to their scroll position
Compatible across modern browsers
There are several plugins that make it easy to add lazy loading to Shopify:
Yotpo - their app has built-in lazy loading for their embedded widgets and images. Just enable in settings.
jQuery Unveil - lightweight jQuery plugin to lazy load images based on scroll position. Needs custom code.
Lazysizes - JavaScript library for lazy loading responsive images, iframes and more. Highly customizable.
To implement lazy loading effectively:
Only lazy load offscreen assets, or assets below the fold. Don't defer loading of critical above-the-fold content.
Lazy load eagerly on mobile to minimize reflows and improve performance on slower connections.
Use placeholder/blurry image versions before full image loads if feasible to improve user experience.
Lazy load widgets like videos or social media embeds that are non-essential to the initial page load.
Lazy loading is an impactful optimization that can significantly improve your Shopify site speed and mobile experience. The key is implementing it judiciously for assets below the fold using a lightweight plugin.
Enable Gzip Compression
Enabling Gzip compression is one of the easiest ways to reduce page sizes and improve site speed. Gzip compresses text-based files like HTML, CSS, JavaScript and images before sending them over to the browser. This significantly reduces the filesize that needs to be transferred, often by 60-70%.
To enable Gzip compression in Shopify:
Go to your Shopify admin, and navigate to Settings > Checkout.
Scroll down and check the box next to Enable Gzip compression.
Click Save to apply the changes.
That's it! Shopify will now compress files with Gzip before serving them to browsers. This happens automatically without any changes needed to your code. Just by toggling this setting, you can achieve significant reductions in page size and load times.
The impact will be especially noticeable for visitors on slower connections. Smaller files mean faster downloads, so enabling Gzip is an easy "quick win" for store speed optimization. It's one of the most basic improvements you can make, but can yield big benefits.
Optimize Database Queries
Database queries can significantly impact the speed and performance of a Shopify store. Identifying and optimizing slow or inefficient database queries is crucial for site speed.
Shopify provides access to database query logs which can be used to analyze query performance. The logs show query execution time, allowing you to identify queries that are taking the longest to run. Slow queries that are repeatedly executed should be optimized first.
Some techniques for optimizing database queries:
Add indexes on commonly queried columns: Adding database indexes will allow queries to locate records faster without scanning the entire table. Frequently queried columns and join keys are good candidates for indexing.
Use caching: Query caching stores the results of database queries so identical queries do not need to be executed again. Memcached or Redis can be used to implement caching for common queries.
Tune problematic queries: Look at the query execution plan to see if you can add limits, optimize joins, or add filters to improve performance. Avoid queries that scan many rows unnecessarily.
Upgrade to a faster database plan: For very large stores, upgrading to a higher Shopify plan with more resources can provide faster database performance. Shopify Plus plans offer dedicated database servers.
Proactively optimizing queries and avoiding slow queries will significantly improve site speed and deliver a better experience for customers. Monitoring query logs and continuously tuning database performance is key for any high-traffic Shopify store.
Conclusion
Optimizing your Shopify store's speed is crucial for providing a great user experience, boosting conversions, and improving SEO. In this guide, we covered several advanced techniques that go beyond the basics:
Minifying code reduces file sizes and speeds up page loading. Shopify has built-in minification, but you can further optimize using tools like CSSNano and Terser.
Implementing asynchronous JavaScript prevents render-blocking and loads scripts without delaying page rendering. Try deferred or async attributes.
Compressing images is essential, but also enable WebP and AVIF formats, lazy load offscreen images, and serve properly sized images. Use tools like ImageOptim.
Enabling caching means resources load from the browser cache instead of fetching from the server each time. Set proper cache lifetimes with a service worker or cache policy.
Reduce unnecessary redirects which incur additional HTTP requests. Avoid chaining redirects, enable 301s over 302s, and consolidate redirect rules.
Lazy load elements like images or embeds that are below the fold. Use native browser features or a library like Lazysizes.
Turn on gzip compression in Shopify for faster transmission of text-based files like HTML, CSS, and JavaScript.
Optimize database queries by reducing API requests, using cache tags, and implementing query optimizations.
The cumulative impact of these advanced optimizations can lead to dramatic speed improvements. Faster stores enjoy higher conversions, improved SEO rankings, lower bounce rates, and happier customers.
Going forward, continuously monitor your site speed and implement optimizations. Speed optimization is an ongoing process as new techniques emerge. With a blazing fast Shopify store, you’ll boost revenue and deliver an excellent user experience.