Repos / pytaku / 7f011a72d4
commit 7f011a72d430ea23244be37e0e39dbe0bdbdd3be
Author: Bùi Thành Nhân <hi@imnhan.com>
Date:   Sun Aug 30 15:56:14 2020 +0700

    try preloading a list instead of single imgs
    
    For some reason the preloaded images didn't get reused when user
    actually visited next chapter. Maybe this helps?

diff --git a/pyproject.toml b/pyproject.toml
index 4a5cb5b..152be7e 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
 [tool.poetry]
 name = "pytaku"
-version = "0.3.13"
+version = "0.3.14"
 description = "Self-hostable web-based manga reader"
 authors = ["Bùi Thành Nhân <hi@imnhan.com>"]
 license = "AGPL-3.0-only"
diff --git a/src/pytaku/static/js/routes/chapter.js b/src/pytaku/static/js/routes/chapter.js
index 987086e..34ef7f8 100644
--- a/src/pytaku/static/js/routes/chapter.js
+++ b/src/pytaku/static/js/routes/chapter.js
@@ -44,7 +44,7 @@ function Chapter(initialVNode) {
   let site, titleId; // these are written on init
   let nextChapterPromise = null;
   let nextChapterPendingPages = null;
-  let nextChapterLoadedPage = "";
+  let nextChapterLoadedPages = [];
 
   function loadNextPage() {
     if (pendingPages.length > 0) {
@@ -71,7 +71,7 @@ function Chapter(initialVNode) {
   function preloadNextChapterPage() {
     if (nextChapterPendingPages !== null) {
       if (nextChapterPendingPages.length > 0) {
-        nextChapterLoadedPage = nextChapterPendingPages.splice(0, 1)[0];
+        nextChapterLoadedPages.push(nextChapterPendingPages.splice(0, 1)[0]);
       } else {
         console.log("Completely preloaded next chapter.");
       }
@@ -215,12 +215,14 @@ function Chapter(initialVNode) {
           ]
         ),
         buttons,
-        m("img.chapter--preloader", {
-          style: { display: "none" },
-          onload: preloadNextChapterPage,
-          onerror: preloadNextChapterPage,
-          src: nextChapterLoadedPage,
-        }),
+        nextChapterLoadedPages.map((page) =>
+          m("img.chapter--preloader", {
+            style: { display: "none" },
+            onload: preloadNextChapterPage,
+            onerror: preloadNextChapterPage,
+            src: page,
+          })
+        ),
       ]);
     },
   };