'Load More' List Template

Improve performance and user experience by incrementally loading items into a long list.

This template uses JavaScript to initially hide most list items, showing more each time the user clicks the "Load More" button.

A list of items with a 'Load More' button at the bottom.

Get Source Code Preview

About this Template

This component provides a client-side solution for progressive list loading. It assumes the full list of items is present in the HTML but uses JavaScript to hide most of them initially. Each click on the "Load More" button reveals a new batch of items. When all items are visible, the button automatically hides itself. This is an excellent technique for improving perceived performance on pages with many list items.

Features

Code Breakdown

The structure consists of a standard unordered list (ul) and a button. The JavaScript handles all the logic.

On page load, the script first hides all list items beyond a predefined initial amount (e.g., the first three). It then attaches a click event listener to the "Load More" button. When the button is clicked, the script finds the next hidden list items and reveals them. This is managed by keeping track of how many items are currently visible. After revealing a new batch, the script checks if there are any remaining hidden items. If not, it hides the "Load More" button.

Code

Here's the full code for the template:

View Output