How to Minify CSS and JavaScript in Shopify (2026)

Last updated
•
Expert reviewed
•
5 min read

Key takeaways

  • Shopify automatically minifies CSS and JavaScript from theme files — you don’t need to do this manually for most code.
  • Shopify’s CDN serves all assets with gzip or Brotli compression enabled.
  • Manual minification is needed for: inline scripts in theme.liquid and custom code blocks added directly to the HTML.
  • Tools: cssnano for CSS, Terser for JavaScript.

Minification removes whitespace, comments, and shortens variable names in code files to make them smaller. Smaller files transfer faster, which improves page load time. The good news for Shopify store owners: most of this happens automatically.

How to minify JavaScript and CSS in Shopify

Short answer: Shopify does it for you.

When you upload or edit CSS and JavaScript files in your Shopify theme, Shopify’s platform automatically minifies them when serving to visitors. The version you see in the code editor is the readable, unminified source — the version sent to browsers is minified.

Additionally, Shopify’s CDN serves all assets with gzip or Brotli compression enabled. This reduces transfer size for all text-based files — HTML, CSS, JavaScript — regardless of whether they’re already minified.


What Shopify minifies automatically

Theme CSS files (e.g., assets/base.css, assets/theme.css) — minified on Shopify’s CDN.

Theme JavaScript files (e.g., assets/theme.js, assets/global.js) — minified on Shopify’s CDN.

Section {% javascript %} blocks — Shopify bundles and minifies these automatically as part of its section rendering pipeline.

Section {% stylesheet %} blocks — similarly handled automatically.


When you need to minify manually

Inline scripts added directly to theme.liquid

If you add a <script> block inline inside theme.liquid (not in an asset file):

<!-- theme.liquid -->
<script>
    // This code is NOT automatically minified by Shopify
    var myStoreConfig = {
        currency: 'USD',
        theme: 'Dark',
    }
</script>

This code is part of the HTML response, not a separate asset file — Shopify doesn’t minify it. For small configuration objects, this is usually fine. For larger inline scripts, minify before pasting.

Third-party scripts you host yourself

If you copy a third-party script into your assets/ folder rather than loading it from an external CDN, Shopify minifies it like any other asset, but upload the library’s .min.js build anyway so the file is small in the code editor too.

Custom code blocks in the Theme Editor

Some themes let you add custom HTML in a “Custom HTML” section block. JavaScript pasted here is not minified by Shopify.

For where custom scripts belong, see how to add custom JavaScript in Shopify.


Tools for manual minification

CSS:

JavaScript:

For production-grade minification (e.g., if you’re developing a theme), use these tools as part of a build pipeline (Webpack, Vite, or Rollup) rather than manually.


Does minification significantly improve Shopify performance?

For theme files — no, because Shopify handles it. For overall performance: image optimization, reducing unused app scripts, and fixing render-blocking resources have far greater impact than minifying the remaining code.

A 30KB CSS file minified to 22KB saves 8KB. Removing a single unused app script that’s 200KB saves 200KB. Focus there first.

Build fast, clean Shopify code with Fudge.
Start free trial

To find and remove that dead code, see how to remove unused code in Shopify.


What actually moves the needle on Shopify performance

These changes save more than minification:

1. Image optimization. Large product images are a common cause of slow Shopify stores. Compress images before uploading. Keep hero images (2560 x 1440px) under 1MB, and product images under 100KB.

2. Removing unused app scripts. Each external app script is an HTTP request to a third-party server. Even if the script is small, the connection overhead adds latency. Remove scripts from apps you no longer use.

3. Fixing render-blocking scripts. Scripts in <head> without async or defer delay page paint. See our guide on optimizing render-blocking scripts.

4. Using a fast base theme. Dawn is built to score well on mobile PageSpeed. Heavily customized or older themes often score lower. Starting from a fast theme is more impactful than optimizing a slow one.

For the full list of speed fixes, see how to speed up a Shopify theme.


Checking your current minification status

Open Chrome DevTools (F12) → Network tab → filter by CSS or JS → click on a file → look at the response body. If it’s minified, you’ll see compressed, hard-to-read code. If it has whitespace and comments, it’s not minified at the CDN level (unusual for Shopify theme files).

For your actual page performance, use PageSpeed Insights — it will flag specific opportunities including any un-minified files it detects.


FAQ

Does Shopify minify CSS and JavaScript in real-time or on theme save?

On serve. Shopify's CDN minifies asset files on the fly when they're requested by browsers — the source file you see in the code editor is unminified for readability, the served file is minified. There's no manual "build" step required for theme assets.

Should I minify code before pasting it into a Shopify theme file?

For theme asset files (assets/*.css, assets/*.js): no — Shopify minifies on serve, and minified source is harder to maintain. For inline <script> tags in theme.liquid or section blocks: yes, since these are inline HTML and Shopify doesn't minify them.

Will minification break my Liquid tags?

Liquid renders before minification, so the HTML and CSS that Shopify minifies have no Liquid syntax left in them. Don't worry about Liquid — minification operates on the rendered output. If you're using a third-party minifier on Liquid source code, that would break — only minify rendered output.

How much speed improvement does minification actually give?

For most Shopify stores, single-digit percentage improvement on file sizes. Real performance gains come from image optimization (often 50%+ reduction), removing unused JavaScript (eliminates entire HTTP requests), and lazy-loading. Minification is a marginal optimization. To find the bigger wins, ask Fudge, the AI operator for Shopify stores, for a speed audit ("audit our homepage for the biggest LCP wins — preload the hero, defer non-critical scripts, lazy-load below-fold images"). It drafts the fixes in your theme for you to approve, and slow pages are one of the issues its SEO checks already look for.

Does Shopify support Brotli compression?

Yes. Shopify's CDN serves text-based assets with Brotli (or gzip as fallback) compression by default. Brotli is more efficient than gzip — typically 15–25% smaller. You don't need to configure this; it's automatic on every Shopify store.

Jacques's signature
Build fast Shopify pages by describing what you need.

You might also be interested in

Jacques Blom
Jacques Blom
CTO at Fudge.