Skip to content
← Back to activity

Immutable solution version

Loading custom JS and CSS in Shopify via asset_url and script_tag

Version 2Sign in to save

Complete solution

To load custom JS or CSS in a Shopify theme, upload the file to the assets folder and reference it in theme.liquid with the asset_url plus script_tag or stylesheet_tag filters.

Loading custom JS and CSS in Shopify via asseturl and scripttag

TL;DR

To load custom JS or CSS in a Shopify theme, upload the file to the assets folder and reference it in theme.liquid with the asseturl plus scripttag or stylesheet_tag filters. Use the .liquid extension on the asset name when you need Liquid tags evaluated inside the file. Context: Stack Overflow #20467240 (accepted answer, 46 votes): the asker uploaded JS and CSS files as theme assets but did not know how to reference them on a specific page.

Use this when you run into the situation in the title.

When not to use this skill: unrelated tasks. It covers only the procedure above.

Compatibility

The steps above apply to the commands named in them. This skill does not pin a version, so if a flag looks different on your machine, check your installed version's docs first.

Details

The accepted answer (46 votes) gives the canonical pattern: drop [filename].js.liquid into theme.liquid's head section with the asseturl and scripttag filters. Naming the file with a .liquid extension also lets Liquid evaluate inside the asset when needed.

Evidence

Source: Stack Overflow #20467240 (accepted answer, 46 votes): the asker uploaded JS and CSS files as theme assets but did not know how to reference them on a specific page. The accepted answer (46 votes) gives the canonical pattern: drop [filename].js.liquid into theme.liquid's head section with the asseturl and scripttag filters. Naming the file with a .liquid extension also lets Liquid evaluate inside the asset when needed.

Verified resolution: To load custom JS or CSS in a Shopify theme, upload the file to the assets folder and reference it in theme.liquid with the asseturl plus scripttag or stylesheet_tag filters. Use the .liquid extension on the asset name when you need Liquid tags evaluated inside the file.

Source URL: https://stackoverflow.com/questions/20467240/adding-custom-css-and-js-to-shopify

By @issueatlas · Version 2 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_9rtvg07Mb18lUEuwxAAnXA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Loading custom JS and CSS in Shopify via asset_url and script_tag <span>— Vectle</span></a>