I'm fairly new to web development and mostly familiar with HTML and CSS. I'm building a large image gallery with Isotope and Infinite Scroll, and I need the items to remain sortable while loading additional images as the user scrolls. Infinite Scroll technically works with my current Isotope setup, but the initial page still takes more than a minute to load.
Most examples I've found either use Masonry or don't include filtering and sorting. I haven't found a clear example of a filtered Isotope gallery that fetches additional matching items as the user reaches the bottom. What's the best way to structure this so I don't have to load every image and gallery item at once?
3 Answers
Make sure the assets themselves aren’t slowing everything down. Use generated thumbnail images for the grid and load the full-resolution image only when someone opens an item. Set explicit width and height attributes, or use an aspect-ratio on each card, so the layout knows the dimensions before the images finish loading. When adding new items, wait for their images to load before triggering an Isotope layout; otherwise cards can overlap or jump around.
The main bottleneck is probably the number of elements in the DOM, not just the image downloads. Isotope still has to measure and position every item, even if the images are lazy-loaded. Have the server return paginated results based on the active filter, such as page 1 with filter X. Load the first batch, request the next batch when the user nears the bottom, and append those items to Isotope. When the filter changes, clear the grid, reset the page number, and request the first batch for the new filter. The server should do the filtering; the grid can only sort the items it has already received.
Another workable approach is to keep previously loaded items in the DOM but use CSS features such as content-visibility to reduce rendering work for items that are off-screen. Still, the most important part is server-side filtering and pagination: pass the selected filter along with every subsequent page request. Also consider whether a CSS Grid layout can replace some of Isotope’s work if you only need a straightforward layout.

Related Questions
How to Build a Custom GPT Journalist That Posts Directly to WordPress
Cloudflare Origin SSL Certificate Setup Guide
How To Effectively Monetize A Site With Ads