Skip to content

Commit

Permalink
Use link[rel=prefetch] to preload chapter pages
Browse files Browse the repository at this point in the history
  • Loading branch information
ObserverOfTime committed Nov 25, 2023
1 parent e316939 commit e3982be
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ v0.9.5
^^^^^^

* Removed Reddit OAuth provider
* Reduced prefetched pages from 3 to 2

v0.9.4
^^^^^^
Expand Down
10 changes: 5 additions & 5 deletions reader/templates/chapter.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
<link href="{% static 'COMPILED/styles/chapter.css' %}"
rel="stylesheet preload" type="text/css" as="style">
{% endblock %}
{% block head_extras %}
{% for page in prefetch %}
<link href="{{ page.image.url }}" rel="prefetch" as="image">
{% endfor %}
{% endblock %}
{% block title %}
<meta name="title" content="{{ curr_chapter.title }}">
{% with title=curr_chapter.series.title|add:' ~ '|add:config.NAME %}
Expand Down Expand Up @@ -128,9 +133,4 @@ <h1>
</section>
{% endwith %}
</div>
<div id="preload" class="no-display">
{% for page in preload %}
<img alt="preload" src="{{ page.image.url }}">
{% endfor %}
</div>
{% endblock %}
6 changes: 3 additions & 3 deletions reader/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ def chapter_page(request: HttpRequest, slug: str, vol: int,
curr_page = next(p for p in all_pages if p.number == page)
except StopIteration as e: # pragma: no cover
raise Http404('No such page') from e
preload = list(filter(
lambda p: curr_page < p < curr_page.number + 4, all_pages
prefetch = list(filter(
lambda p: curr_page < p < curr_page.number + 3, all_pages
))
tags = current.series.categories.values_list('name', flat=True)
url = request.path
Expand All @@ -237,7 +237,7 @@ def chapter_page(request: HttpRequest, slug: str, vol: int,
'prev_chapter': prev_,
'all_pages': all_pages,
'curr_page': curr_page,
'preload': preload,
'prefetch': prefetch,
'breadcrumbs': crumbs,
'tags': ','.join(tags)
})
Expand Down

0 comments on commit e3982be

Please sign in to comment.