Skip to content

Commit a82d835

Browse files
committed
Lazy-load plot images and reserve their layout space
Every plot image but the first one now loads lazily and decodes off the main thread, so a visit only fetches what the reader scrolls to. The width/height attributes come from the rendered image, which keeps the cards from collapsing and reflowing as images arrive. Also adds alt text, which the images never had.
1 parent 32f4db5 commit a82d835

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

‎templates/t_index.html‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ <h5>{{ name }}</h5>
107107
<hr>
108108
<div class="row mt-4" id="examples"><div class="col-xs-12 col-md-10 offset-md-1">
109109
{% for (name, slug), items in plots.items() %}
110+
{% set outer_loop = loop %}
110111
<section id="{{ slug }}">
111112
<div class="card mb-4">
112113
<div class="card-header">
@@ -124,12 +125,13 @@ <h3 class="card-title mb-1"><a href="#{{ slug }}"><i class="fa fa-link" aria-hid
124125
<div class="card-block p-0">
125126
<div class="tab-content">
126127
{% for plot in items %}
128+
{% set eager = outer_loop.first and loop.first %}
127129
<div class="tab-pane {% if loop.index0 == 0 %} active{% endif %}" id="{{ slug }}{{ plot['package-slug'] }}" role="tabpanel">
128130
<div class="container-fluid">
129131
<div class="row">
130132
<div class="col-lg-6 col-xs-12 p-lg-0">
131133
<a href="{{ plot['image'] }}" data-toggle="lightbox" data-title="{{ name }} - {{ plot['package'] }}">
132-
<img src="{{ plot['image'] }}" class="img-fluid">
134+
<img src="{{ plot['image'] }}" class="img-fluid" alt="{{ name }} drawn with {{ plot['package'] }}" width="{{ plot['image-width'] }}" height="{{ plot['image-height'] }}" decoding="async"{% if not eager %} loading="lazy"{% endif %}>
133135
</a>
134136
</div>
135137
<div class="col-lg-6 col-xs-12 p-0 right-col d-inline-flex flex-column">

0 commit comments

Comments
 (0)