Lars
Lars

Reputation: 1270

How to Preload only few images in Django

I am Building a BlogApp and I want my Image Page to load only few images after open the Image.

What i am trying to do:-

I am trying to Load only 9 images in the Server. I mean :- When user opens the Page then, load only few images that are in front of the page, and if user scrolls then load next few images.

What is happening Now:-

When i open the server now, It loads all the Images that are uploaded in the Page. AND i don't want to load all the Images in the Page.

What have i tried:-

I don't know what to do.

Any help would be appreciated.

Thank You in Advance.

Upvotes: 0

Views: 523

Answers (1)

Abdul Aziz Barkat
Abdul Aziz Barkat

Reputation: 21797

Basically you want to lazily load images. You can set loading="lazy" to do that.

<img src="{{ image.file.url }}" width="200" loading="lazy">

This will cause the browser to wait until user scrolls near the image to load it.

Reference: Lazy loading

Upvotes: 1

Related Questions