How to Add Infinite Scroll to a Shopify Collection Page (Without Apps)

How to Add Infinite Scroll to a Shopify Collection Page (Without Apps)


Infinite scroll loads more products automatically as shoppers reach the bottom of a collection page β€” eliminating the need for pagination buttons. This tutorial shows how to add infinite loading using Liquid + JavaScript, compatible with Dawn and most modern Shopify themes.

Everything here is safe, reversible, and requires **no apps**.


πŸ“Œ Step 1 β€” Enable Pagination in Your Collection Template

Your theme must already have pagination for infinite scroll to work.

Go to:

Online Store β†’ Themes β†’ Edit Code β†’ templates/collection.json

Make sure a collection section is added (most themes have main-collection-product-grid).

If pagination is disabled, enable it inside the Theme Editor β†’ Collection Page β†’ Product Grid settings.

Infinite scroll works by auto-clicking the β€œNext page” URL in your pagination block.

πŸ“Œ Step 2 β€” Locate the Pagination Block

Open the collection section file:

sections/main-collection-product-grid.liquid

Look for something like:

{% paginate collection.products by 24 %}
  ...
  {% render 'pagination', paginate: paginate %}
{% endpaginate %}

This paginate block is what infinite scroll will hook into.


πŸ“Œ Step 3 β€” Add a Wrapper for Product Grid (Required)

Find your product grid markup and ensure it has an ID or class you can target:

<div id="product-grid" class="product-grid">
  ... products here ...
</div>

If your theme already uses id="product-grid" leave it unchanged.


πŸ“Œ Step 4 β€” Add the Infinite Scroll JavaScript

Open:

assets/global.js or theme.js

Add this script at the bottom:

document.addEventListener('DOMContentLoaded', () => {

  const grid = document.querySelector('#product-grid');
  if (!grid) return;

  let loading = false;

  const loadMoreProducts = () => {
    const nextPageLink = document.querySelector('.pagination__next');
    if (!nextPageLink || loading) return;

    loading = true;

    fetch(nextPageLink.href)
      .then(response => response.text())
      .then(html => {
        const parser = new DOMParser();
        const doc = parser.parseFromString(html, 'text/html');

        const newProducts = doc.querySelector('#product-grid').innerHTML;
        const newPagination = doc.querySelector('.pagination').innerHTML;

        grid.insertAdjacentHTML('beforeend', newProducts);

        document.querySelector('.pagination').innerHTML = newPagination;

        loading = false;
      });
  };

  const observer = new IntersectionObserver((entries) => {
    if (entries[0].isIntersecting) {
      loadMoreProducts();
    }
  }, {
    rootMargin: '200px'
  });

  const sentinel = document.createElement('div');
  sentinel.id = 'infinite-scroll-trigger';
  grid.after(sentinel);

  observer.observe(sentinel);

});

This script:

  • Detects when the user scrolls near the bottom
  • Loads the next page using AJAX
  • Appends products automatically
  • Updates pagination invisibly (required for next fetch)

πŸ“Œ Step 5 β€” Style the Loading State (Optional)

Add a small loading animation under assets/base.css:

#infinite-scroll-trigger::after {
  content: 'Loading more products...';
  display: block;
  text-align: center;
  padding: 20px;
  font-size: 14px;
  color: #666;
}

You can customize this however you like.


πŸ“Œ Step 6 β€” Remove Pagination Buttons (Optional)

If you want pagination hidden entirely, add this to your CSS:

.pagination {
  display: none !important;
}

πŸ§ͺ Step 7 β€” Test Infinite Scroll

  • Does the next batch of products load when scrolling?
  • Does the loading state show up?
  • Does it stop loading when there are no more pages?
  • Is mobile scroll performance smooth?

⚠️ Troubleshooting

1. Infinite scroll doesn’t trigger? – Ensure the selector #product-grid exists – Ensure your pagination has a link with class pagination__next

2. Products duplicate? – Your grid selector might be incorrect. Check your HTML.

3. Nothing loads? – Your theme might use a different pagination snippet. Tell me your theme name and I will generate theme-specific code.

πŸŽ‰ You’re Done!

Your Shopify collection page now loads products automatically β€” creating a smooth, modern browsing experience similar to big brands like Zara, H&M, and Amazon.

Β 

Β 

Back to blog

Leave a comment