Hi Kyle
I like to ask why. So here goes (sorry)
First I would ask the customer "Why do you need infnite scroll" and what prove exist to back their answer?. Then I would try to explain that they should consider twice before implementing because it probably will not improve their webshop and result in more sales.
My guess is that it is a business and they want to make more money. So implementing infinite scroll should provide more revenue than the cost of implementing it? Just a guess. Do the math backed by research and you have the answer.
Research on infnite scroll in Commerce:
I have worked with enough customers to understand that the above is rational thinking - and they do not care. So they want it regardless.
Implementing infinite scroll in Dynamicweb 10
A good way to implement infinite scroll on a server-side rendered product list is to treat it as progressive enhancement:
-
Render page 1 normally on the server.
-
Add a small client-side script that detects when the visitor approaches the bottom of the list.
-
Fetch page 2, 3, 4, etc. from the product search API.
-
Append those products to the existing list.
-
Stop when the API no longer returns products.
This gives you a normal SSR product page for the initial request, while subsequent pages can be loaded without doing a full navigation.
1. Keep the first page server rendered
Your initial PLP could still be requested normally:
/products/bikes?PageSize=24&CurrentPage=1
The server renders the first 24 products, filters, facets, sorting, etc.
At the bottom of the product list, add a sentinel element:
<div id="product-list">
<!-- Products rendered by the server -->
</div>
<div id="product-scroll-sentinel"></div>
The sentinel is simply an element we can observe to determine when the user is getting close to the bottom.
It is also a good idea to keep a normal Load more link or button as a fallback. Infinite scroll can then enhance that behaviour rather than being the only way to navigate the catalog.
2. Use CurrentPage and PageSize
For /dwapi/ecommerce/products/search, the pagination parameters are:
PageSize=24
CurrentPage=2
CurrentPage is 1-based, so:
CurrentPage=1 -> products 1-24
CurrentPage=2 -> products 25-48
CurrentPage=3 -> products 49-72
I would use CurrentPage for product-search pagination.
There is also a PageNum parameter in the API model, but unless the particular feed/search implementation you are using specifically requires it, don't send both PageNum and CurrentPage. CurrentPage is the parameter explicitly documented for pagination on this endpoint.
3. Request only the data you need
For subsequent pages there is normally no reason to request the entire product search ViewModel.
For example:
/dwapi/ecommerce/products/search
?GroupId=GROUP49
&PageSize=24
&CurrentPage=2
&FilledProperties=Products
You can additionally use ProductSettings.FilledProperties to limit the properties returned for each product.
For example, depending on what your product card needs:
ProductSettings.FilledProperties=Id,Name,Price,DefaultImage
The exact properties obviously depend on your product card.
Remember to send the same context as the original product list, including things such as:
GroupId
RepositoryName
QueryName
ShopId
CurrencyCode
LanguageId
filters
sorting
Otherwise page 2 may not represent the same query as page 1.
4. Detect when the next page should be loaded
You don't need scroll-event calculations for this.
Use IntersectionObserver:
const sentinel = document.querySelector("#product-scroll-sentinel");
const observer = new IntersectionObserver(
entries => {
if (entries.some(entry => entry.isIntersecting)) {
loadNextPage();
}
},
{
rootMargin: "600px"
}
);
observer.observe(sentinel);
rootMargin: "600px" means loading can begin before the visitor actually reaches the bottom.
This generally feels nicer than waiting until the final product is already visible.
5. Fetch the next page
Keep a small amount of state:
let currentPage = 1;
let loading = false;
let hasMoreProducts = true;
Then something along these lines:
async function loadNextPage() {
if (loading || !hasMoreProducts) {
return;
}
loading = true;
try {
const nextPage = currentPage + 1;
const url = new URL(
"/dwapi/ecommerce/products/search",
location.origin
);
url.searchParams.set("GroupId", "GROUP49");
url.searchParams.set("PageSize", "24");
url.searchParams.set("CurrentPage", String(nextPage));
url.searchParams.set("FilledProperties", "Products");
const response = await fetch(url, {
headers: {
Accept: "application/json"
}
});
if (!response.ok) {
throw new Error(`Product request failed: ${response.status}`);
}
const data = await response.json();
const products = data.Products ?? [];
if (products.length === 0) {
hasMoreProducts = false;
observer.disconnect();
return;
}
appendProducts(products);
currentPage = nextPage;
if (products.length < 24) {
hasMoreProducts = false;
observer.disconnect();
}
} finally {
loading = false;
}
}
The important parts here are not really the exact code, but the state:
currentPage
loading
hasMoreProducts
Without loading, the observer can trigger several requests for the same page before the previous request has completed.
6. Include authentication when prices are personalized
The search endpoint can be called anonymously, but authenticated users may receive user/customer-group specific prices and discounts.
If the browser already has a JWT that is intended to be used client-side, add it to the request:
const response = await fetch(url, {
headers: {
Accept: "application/json",
Authorization: `Bearer ${jwt}`
}
});
Then pages loaded through infinite scroll use the same pricing context as the authenticated visitor.
Be careful not to take a token that is supposed to remain server-side and expose it to browser JavaScript just to implement infinite scroll.
If authentication is handled by your own server, another option is to have the browser call an endpoint on your application and let the server make the authenticated Dynamicweb request.
Also make sure authenticated product/pricing responses cannot accidentally be shared through a cache with anonymous or other authenticated users.
7. Keep all filters and sorting when loading page 2
This is probably the easiest bug to introduce.
Suppose the visitor is currently looking at:
/products
?brand=Rapha
&color=black
&sort=price
Page 2 must execute the same search, only with:
CurrentPage=2
Don't construct a completely new product query containing only the page number.
Usually I would create the API URL based on the current PLP state:
const pageUrl = new URL(location.href);
const apiUrl = new URL(
"/dwapi/ecommerce/products/search",
location.origin
);
// Transfer the filters/search state that applies to the API...
apiUrl.searchParams.set("PageSize", "24");
apiUrl.searchParams.set("CurrentPage", String(nextPage));
If your PLP has client-side filters, keep one canonical search-state object and use that both when changing filters and when loading subsequent pages.
When a filter changes:
1. Abort any current product request
2. Clear the existing results if appropriate
3. Set CurrentPage back to 1
4. Execute the new search
5. Re-enable the observer
AbortController is useful for this:
let controller;
async function loadProducts(url) {
controller?.abort();
controller = new AbortController();
const response = await fetch(url, {
signal: controller.signal
});
// ...
}
8. Append product cards
If the API returns JSON, you need to render the returned products into your product-card markup.
For example:
function appendProducts(products) {
const list = document.querySelector("#product-list");
const fragment = document.createDocumentFragment();
for (const product of products) {
const article = document.createElement("article");
// Populate your product card here.
// Prefer DOM APIs/templates rather than concatenating
// untrusted strings into innerHTML.
fragment.append(article);
}
list.append(fragment);
}
A <template> element is also useful if the client-rendered product cards closely match the server-rendered markup.
An alternative architecture is to expose a server endpoint that renders the next batch of product-card HTML rather than JSON. That can be attractive if maintaining identical product-card rendering in both server code and JavaScript would otherwise result in duplicated templates.
The flow would then be exactly the same:
IntersectionObserver
↓
request next page
↓
receive HTML
↓
append HTML
instead of mapping JSON into product-card markup in JavaScript.
9. Stop observing when there are no more products
If your response exposes a total product count or page count, use that.
Otherwise the simple fallback is:
if (products.length < pageSize) {
hasMoreProducts = false;
observer.disconnect();
}
And, of course, an empty result means there are definitely no more pages:
if (products.length === 0) {
observer.disconnect();
}
10. Think about browser history
Pure infinite scroll has one annoying behaviour:
Visitor scrolls to page 5
→ opens a product
→ presses Back
→ ends up back at page 1
Consider recording how far the visitor has progressed.
A simple option is:
history.replaceState(
{ currentPage },
"",
`?page=${currentPage}`
);
Your exact URL strategy depends on how the PLP routing works, but having a restorable page position makes infinite scroll much nicer.
For larger catalogs you may also want to avoid keeping hundreds of product DOM nodes alive indefinitely. That is a separate optimisation and usually isn't necessary for the first implementation.
Suggested overall architecture
In short:
GET /products/bikes
↓
Server renders products 1-24
↓
Browser observes sentinel
↓
GET /dwapi/ecommerce/products/search?...&CurrentPage=2
↓
Append products 25-48
↓
Sentinel becomes visible again
↓
CurrentPage=3
↓
...
I would keep the implementation deliberately boring:
-
SSR for the initial page.
-
IntersectionObserver for triggering loads.
-
fetch() for subsequent pages.
-
URL / URLSearchParams for query construction.
-
AbortController when searches or filters can change.
-
A loading flag to prevent duplicate requests.
-
Stop the observer when no more products are available.
-
Send the JWT on API requests when authenticated pricing is required.
-
Preserve exactly the same shop, currency, language, filters and sorting across every page.
-
Keep a normal pagination/Load More path as a fallback where practical.
That gives you infinite scrolling without changing the fundamental server-rendered PLP architecture.