Performance best practices for Shopify apps
Performance is an important factor for merchants when they choose an app for their online store. When you build an app, you should build with performance in mind.
Optimizing your app for performance is key to the success of the merchants that you support and to the experiences of their customers. Performance directly influences conversion rates, repeat business, and search engine rankings.
Optimizing for performanceAnchor link to section titled "Optimizing for performance"
Consider the following best practices for optimizing the performance of your app.
Use theme app extensionsAnchor link to section titled "Use theme app extensions"
Theme app extensions allow developers to extend themes in a way that protects theme code integrity and provides better app development and merchant experiences.
Apps built in the theme app extension framework don't edit theme code, which decreases the risk of introducing breaking changes to the theme, makes it easier to iterate on the content of the integration, and provides for a better merchant experience.
All files inside the
assets/ folder are automatically served from Shopify's CDN for fast, reliable asset delivery. Reference your assets by using either the
stylesheet schema attributes or using the
asset_img_url Liquid URL filters.
For app embed blocks, take advantage of their ability to only load scripts on specific pages.
Avoid parser-blocking scriptsAnchor link to section titled "Avoid parser-blocking scripts"
Parser-blocking scripts block the construction and rendering of the DOM until the script is loaded, parsed, and executed. They also create congestion on the network and significantly delay page rendering. This impacts metrics like First Contentful Paint and Largest Contentful Paint. You should use
async attributes on script tags to avoid this.
If the order of execution of the script tags matters, then use
If the order of execution doesn't matter, then use
Host assets on Shopify serversAnchor link to section titled "Host assets on Shopify servers"
Deliver as much as you can from the Shopify content delivery network (CDN). Using the same host for your assets avoids unnecessary HTTP connections and allows the server to prioritize delivery of blocking resources using HTTP/2 prioritization.
In a Shopify context, you can do this by using the
AssetREST Admin API resource to host your static files on Shopify's servers and have them delivered by our globally available CDN.
CDNs are accelerated web servers with built-in caching, compression, fast performance, and global distribution. Using Shopify’s CDN also reduces network congestion.
Reduce your dependency on external frameworks and librariesAnchor link to section titled "Reduce your dependency on external frameworks and libraries"
Frameworks such as React, Angular, and Vue, and large utility libraries such as jQuery have significant performance costs. A store's load time is degraded even further when multiple apps try to install the same framework multiple times on the same store.
Avoid introducing polyfill libraries for very old browsers (anything that doesn't support
await). If you use a browserslist, then you can target browsers with a > 1% marketshare.
Load non-critical resources on interactionAnchor link to section titled "Load non-critical resources on interaction"
Your page might contain code for a component or resource that isn't always used. You can load these resources using an import on interaction pattern to avoid loading, parsing, and executing unnecessary code.
Minimize your bundle sizeAnchor link to section titled "Minimize your bundle size"
Browsers can't render a page until the stylesheets are downloaded, parsed, and applied. Inline script tags run only after the stylesheets are loaded. When a remote stylesheet is included before an inline script tag, the stylesheet blocks the script tag from running.
Always include the inline script tags before the stylesheets, like in the following example:
Testing for performanceAnchor link to section titled "Testing for performance"
The tool used by Shopify to test app performance is Lighthouse. Lighthouse is an open-source, automated tool for improving the quality of web pages. It's available in the Developer Tools panel of Google Chrome, so you can test your app directly in the browser.
When you submit an app to the Shopify App Store, the app's tested on a benchmark shop to determine its performance score. To be published in the Shopify App Store, your app must not reduce Lighthouse performance scores by more than 10%.
Test your app in Google ChromeAnchor link to section titled "Test your app in Google Chrome"
- Start with a clean install of a supported Shopify theme, such as Express, without your app or any other apps installed.
- From the home page of your test store, open Developer Tools in Chrome (View > Developer > Developer Tools).
- In Developer Tools, click the Lighthouse tab.
Select Mobile from the device list, then click Generate Report.
Write down the performance score out of 100. This is your starting score.
Install your app on your test store and verify that it loads correctly.
Go to the Lighthouse tab, and click the Generate Report button.
Write down the new performance score. This is your ending score.
Divide your ending score by your starting score. The result is your app's performance ratio.
For example, if your starting score was 84, and your ending score was 72, then you would calculate 72 / 84 to see that your app’s performance ratio is 0.85.
- Learn how to submit your app to the Shopify App Store.