Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preload Image #184

Open
kiranavaibe opened this issue Oct 23, 2024 · 3 comments
Open

Preload Image #184

kiranavaibe opened this issue Oct 23, 2024 · 3 comments

Comments

@kiranavaibe
Copy link

Hi @gerhardsletten ,

I have an EPUB with some images, and during page navigation, it takes a while to load and display the images, resulting in a white screen. Do you have any ideas on how to preload images to eliminate the loading time?

@gerhardsletten
Copy link
Owner

@kiranavaibe React-reader uses epubjs under the hood, and this will load the whole chapter into the dom, and as long as the img-tags not having loading=lazy the browser should start loading images for the current chapter.

In this screenshot i navigate to a new chapter, and in the network-tab 2 images are loaded. The last one will appear on 2 pages ahead.

image

@kiranavaibe
Copy link
Author

@gerhardsletten Thanks for the response! Yes, I understand that images load on page navigation. However, likely due to the image size, there’s a brief white screen before the image appears. I’m wondering if there’s any technique to preload an image in advance to reduce that white screen time.

@gerhardsletten
Copy link
Owner

In this example it shows how to hook into the dom of the iframe where content is rendered: https://github.com/gerhardsletten/react-reader/blob/main/src/examples/DisableContextMenu.tsx

In the same way you could try to hook into each image and display a loader until all is loaded

https://stackoverflow.com/questions/11071314/javascript-execute-after-all-images-have-loaded

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants