Skip to content

Commit

Permalink
fix: Don't load thumbnail too often
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed Nov 5, 2022
1 parent 0f23b9d commit 88e58af
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
6 changes: 5 additions & 1 deletion cmd/fibr/static/scripts/async-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ document.addEventListener(
return;
}

if (typeof fetchThumbnail === 'undefined' || !fetchThumbnail) {
return;
}

let dateTimeFormatter = new Intl.DateTimeFormat(navigator.language, {
dateStyle: 'full',
timeStyle: 'long',
Expand Down Expand Up @@ -145,7 +149,7 @@ document.addEventListener(
);

window.addEventListener('thumbnail-done', () => {
if (typeof lazyLoad === 'undefined' || !lazyLoad) {
if (typeof lazyLoadThumbnail === 'undefined' || !lazyLoadThumbnail) {
return;
}

Expand Down
6 changes: 6 additions & 0 deletions cmd/fibr/templates/files.html
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,12 @@
{{ end }}
</li>
{{ end }}

{{ if and (eq .Request.Display "grid") .HasThumbnail }}
<script type="text/javascript" nonce="{{ .nonce }}">
const fetchThumbnail = true;
</script>
{{ end }}
</ul>
</div>

Expand Down
3 changes: 2 additions & 1 deletion cmd/fibr/templates/story.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
{{ $root := . }}

<script type="text/javascript" nonce="{{ .nonce }}">
const lazyLoad = true;
const fetchThumbnail = true;
const lazyLoadThumbnail = true;
</script>

<link rel="preload" as="image" href="{{ url "/svg/link?fill=#272727" }}">
Expand Down

0 comments on commit 88e58af

Please sign in to comment.