Skip to main content

How To Load Rebuy JS Only On Specific Pages

Load Rebuy only on the pages where you use it, with Rebuy widget app blocks or a page condition in your theme code, while the Rebuy Connector keeps passing customer details.

Written by Christian Sokolowski

To load Rebuy only on specific pages of your Shopify store, such as your product pages, you can use Rebuy widget app blocks or add the Rebuy script to your theme code with a condition that names those pages. With either method, you then turn off Enable Rebuy JS via Rebuy Connector (formerly Install Rebuy Script Tag and Disable Rebuy JS) so the Rebuy Connector stops loading Rebuy on every page.

  • With widget app blocks, no theme code. Rebuy loads only on pages that have a Rebuy widget app block. This method needs an Online Store 2.0 theme.

  • With your own theme code. Rebuy loads only on the page types you name in a condition in layout/theme.liquid. This method works on Online Store 2.0 and vintage themes.

Most stores do not need this setup. Loading Rebuy on every page through the Rebuy Connector is the recommended and fastest setup, described in Load Rebuy Faster. To load Rebuy on specific themes or hide it from customers with a specific tag, see How to conditionally load Rebuy for certain users or on specific themes only.

Rebuy features only work on pages where Rebuy loads

When you load Rebuy only on specific pages, Rebuy storefront features only appear on those pages. Smart Cart, Smart Search, widgets, Smart Flows, and other Rebuy storefront features do not run on a page where Rebuy is not loading. For example, if Rebuy loads only on product pages, a shopper who clicks the cart icon on your home page sees your theme's own cart instead of Smart Cart.

If your store uses Smart Cart or Smart Search, load Rebuy on every page instead. Checkout Extensions and Post-Purchase offers keep working on every order either way, since they do not use Rebuy's storefront script.

Load Rebuy on specific pages with widget app blocks

To load Rebuy only on the pages where your widgets appear, with no theme code, place your Rebuy widgets as app blocks and turn off Enable Rebuy JS via Rebuy Connector. Each Rebuy widget app block loads Rebuy on the page where it is placed, so Rebuy loads only on pages that have a Rebuy widget app block. App blocks need an Online Store 2.0 theme.

  1. Place each Rebuy widget as an app block on the pages where you want it, following Installing Rebuy Widgets via App Blocks in 2.0 Themes.

  2. Search your theme code for rebuy.js. If a <script> tag in your theme loads rebuy.js, remove that tag, since it loads Rebuy on every page it appears on.

  3. In the Rebuy admin, go to the Settings tab and select App Settings.

  4. In the Load Rebuy through the Rebuy Connector panel at the top of the page, turn off Enable Rebuy JS via Rebuy Connector. This setting saves as soon as you turn it off, with no Save button. It applies to your whole store, so the Rebuy Connector stops loading Rebuy on every theme, and only your Rebuy widget app blocks load Rebuy.

  5. Leave the Rebuy Connector app embed on in your theme's App embeds. With Enable Rebuy JS via Rebuy Connector off, the Rebuy Connector no longer loads Rebuy, but it still passes customer and market details, such as customer tags, country, and language, to Rebuy.

  6. Leave Enable Rebuy JS via script tag (legacy, ends Mar 1, 2027) in the General Settings section as it is.

  7. Check which pages Rebuy loads on, using the steps in the section on checking where Rebuy loads below.

Turning off Enable Rebuy JS via Rebuy Connector also permanently removes your store's Shopify script tag, so the legacy setting no longer loads Rebuy on every page either. From October 1st, 2026, Shopify does not let Rebuy add that script tag back.

Load Rebuy on specific pages, Rebuy App Settings with Enable Rebuy JS via Rebuy Connector turned off so the Rebuy Connector stops loading Rebuy on every page


Load Rebuy on specific pages with your own theme code

To load Rebuy on specific pages with theme code, add the Rebuy script to your theme's layout/theme.liquid file inside a condition that names the page types where you want Rebuy, then turn off Enable Rebuy JS via Rebuy Connector. This method works on Online Store 2.0 and vintage themes, since every Shopify theme uses layout/theme.liquid as its layout. Rebuy code you add to your own theme files is not a Shopify script tag, so Shopify's script tag changes on October 1st, 2026 and March 1st, 2027 do not affect it.

Add the script before you turn off Enable Rebuy JS via Rebuy Connector. If you turn the setting off first, Rebuy stops loading on your store until your script is in place.

Rebuy Support can explain these steps but does not edit theme code, so you or your own developer make the changes. Test them on an unpublished copy of your theme first.

Step 1: Add the Rebuy script with a page condition

To load Rebuy on chosen page types, paste the Rebuy script into layout/theme.liquid inside a condition on the page's template name.

  1. In your Shopify admin, go to Sales channels > Online Store, click the ... button next to your theme, and select Edit code.

  2. Open layout/theme.liquid.

  3. Find the <meta charset> tag near the top of the file, inside the <head>. Press Cmd+F on a Mac or Ctrl+F on Windows and search for charset.

  4. Paste the code below on the line directly below the <meta charset> tag.

  5. Change the template names in the first line to the page types where you want Rebuy, and click Save.

{% if template.name == 'product' or template.name == 'cart' %}
<link rel="preconnect" href="https://cdn.rebuyengine.com">
<link rel="preconnect" href="https://rebuyengine.com" crossorigin>
<link rel="preconnect" href="https://cached.rebuyengine.com" crossorigin>
<script async src="https://cdn.rebuyengine.com/onsite/js/rebuy.js?shop={{ shop.permanent_domain }}"></script>
{% endif %}

This example loads Rebuy on product pages and the cart page only, from the <head> of the page, so Rebuy starts loading on those pages as early as it does through the Rebuy Connector. To add another page type, add or template.name == 'name' before %} in the first line, using a template name from the table below.

The following table lists common Shopify pages and the template name to use for each in the condition.

Shopify page

Template name

Home page

index

Product pages

product

Collection pages

collection

Cart page

cart

Search results page

search

Pages you create under Online Store > Pages

page

Step 2: Turn off Rebuy's automatic loading

After your script is in place, turn off Enable Rebuy JS via Rebuy Connector so the Rebuy Connector stops loading Rebuy on every page of every theme, leaving your script as the only thing that loads Rebuy outside your Rebuy widget app blocks.

  1. In the Rebuy admin, go to the Settings tab and select App Settings.

  2. In the Load Rebuy through the Rebuy Connector panel at the top of the page, turn off Enable Rebuy JS via Rebuy Connector. This setting saves as soon as you turn it off, with no Save button.

  3. Leave the Rebuy Connector app embed on in your theme's App embeds. With Enable Rebuy JS via Rebuy Connector off, the Rebuy Connector no longer loads Rebuy, but it still passes customer and market details, such as customer tags, country, and language, to Rebuy.

  4. Leave Enable Rebuy JS via script tag (legacy, ends Mar 1, 2027) in the General Settings section as it is. Turning off Enable Rebuy JS via Rebuy Connector permanently removes your store's Shopify script tag, so the legacy setting no longer loads Rebuy on every page.

Rebuy widget app blocks still load Rebuy on any page where they are placed, even when that page is not in your condition. To keep Rebuy off a page, remove any Rebuy widget app block from that page's template.

If you publish a different theme later, add the same code to that theme's layout/theme.liquid before you publish it. Enable Rebuy JS via Rebuy Connector applies to every theme, so a theme without the code loads Rebuy only where it has Rebuy widget app blocks.


Check which pages Rebuy loads on

To check which pages Rebuy loads on, look for rebuy.js in your browser's developer tools on a page where you want Rebuy and on a page where you do not.

  1. Open a page of your store where you want Rebuy to load.

  2. Right-click the page, select Inspect, and open the Network tab.

  3. Type rebuy.js in the filter box and reload the page. rebuy.js appears in the list when Rebuy loads on that page.

  4. Repeat on a page where you do not want Rebuy. rebuy.js should not appear.

Rebuy console banner showing Rebuy is loaded in

If rebuy.js still loads on a page you did not choose, something else on your store is still loading Rebuy there. Check each of these:

  1. Enable Rebuy JS via Rebuy Connector is off in Settings > App Settings.

  2. No Rebuy widget app block is placed on that page's template.

  3. Your theme code has no other <script> tag that loads rebuy.js outside your condition. Search your theme code for rebuy.js.

  4. You are checking your published theme, since a theme preview shows that theme's own code and app blocks.


Switch back to loading Rebuy on every page

To load Rebuy on every page again, turn the Rebuy Connector setup back on and remove the code you added.

  1. Check that the Rebuy Connector is on in App embeds for your published theme.

  2. In the Rebuy admin, go to Settings > App Settings and turn on Enable Rebuy JS via Rebuy Connector.

  3. Open your store and check that your Rebuy features appear on every page.

  4. If you used the theme code method, remove the conditional Rebuy script from layout/theme.liquid and click Save. Leaving it in place does not break your store, but it makes the browser download Rebuy twice on those pages.


FAQs

Do Rebuy Widget app blocks load Rebuy when the Rebuy Connector is off?

Yes, a Rebuy Widget app block loads Rebuy on the page where it is placed even when the Rebuy Connector app embed is off and Enable Rebuy JS via Rebuy Connector is off. No Rebuy setting turns this off, so the only way to stop a Rebuy Widget app block from loading Rebuy is to remove the block from that page's template. This is what lets the app block method in this article load Rebuy only on pages with a Rebuy widget.


Why do I need the Rebuy Connector if Rebuy Widget app blocks load Rebuy?

You need the Rebuy Connector to load Rebuy on every page of your store, since a Rebuy Widget app block loads Rebuy only on the page where it is placed. Rebuy features that run across your store, such as Smart Cart and Smart Search, need Rebuy on every page a shopper visits, not only on pages with a widget. The Rebuy Connector also loads Rebuy from the <head> of the page, so Rebuy starts loading as soon as the browser starts reading the page, and it passes customer and market details, such as customer tags, country, and language, to Rebuy. Rebuy Widget app blocks do not pass these details. When a page has both, Rebuy runs once, since Rebuy stops any extra copy right away.

Did this answer your question?