Elektrine lite

← Feed

@normplum@fosstodon.org

Post #1158405

2026-04-13 06:19 UTC

If I have a static HTML page that displays hundreds of items (where each item is some text, an image and a link), is there any benefit to add JS client-side pagination? As I understand it, all content will be loaded regardless, the JS will just show/hide certain items as you click on the page links... Or is it ok to just leave the hundreds of items as-is? Or is there a better solution? #WebDev #pagination #pager #JS #Javascript #HTML

Replies (2)

  • @mateus@tech.lgbt 2026-04-13 07:05

    @normplum@fosstodon.org the main benefit would be not downloading the hundreds of images. If the user never advances past the first page, they never need to download more than the first page's images. Depending on the size of the images, that could save tons of bandwidth. A few lines of purpose-built JS could go a long way. But, pulling in a huge library for that purpose would negate the savings. So, choose carefully

    Open ##2898677

  • @idiomatic@mastodon.social 2026-04-13 08:27

    @normplum@fosstodon.org If you're concerned about loading a ton of images all at once, when the user might not even scroll down to see them, you could just pop `loading="lazy"` on each ``. You'll also need the width and height attributes, if you know them, to support Firefox. This should defer the request for each of those unseen images until they're actually in the viewport. Whether this is the right solution depends on the specifics of your project, but it's simpler than implementing pagination!

    Open ##2898683