Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add image lazypreloading

dominik-zeglend1ef73ab9273
diff --git a/saleor/static/js/components/misc.js b/saleor/static/js/components/misc.js
index 1a9495e245..6b9abf0037 100644
--- a/saleor/static/js/components/misc.js
+++ b/saleor/static/js/components/misc.js
@@ -26,4 +26,7 @@ export default $(document).ready((e) => {
let hash = window.location.hash;
$('.nav-tabs a[href="' + hash + '"]').tab('show');
+
+ // Preload all images
+ window.lazySizesConfig.preloadAfterLoad = true;
});
diff --git a/templates/account/login.html b/templates/account/login.html
index 5d598297cd..f3e5f055dc 100644
--- a/templates/account/login.html
+++ b/templates/account/login.html
@@ -14,7 +14,7 @@
<div class="col-md-6 login__register">
<div class="login__register-link">
<h3>{% trans "Don't have an account yet?" context "Login form secondary title" %}</h3>
- <img class="lazyload"
+ <img class="lazyload lazypreload"
data-src="{% static 'images/login-bg.png' %}"
data-srcset="{% static 'images/login-bg.png' %} 1x, {% static 'images/login-bg2x.png' %} 2x">
<a rel="nofollow" href="{% url 'account_signup' %}" class="btn secondary narrow">
diff --git a/templates/account/password_reset.html b/templates/account/password_reset.html
index 526ccdf7a5..6de0860b7e 100644
--- a/templates/account/password_reset.html
+++ b/templates/account/password_reset.html
@@ -29,7 +29,7 @@
<button class="btn primary narrow">
{% trans "Continue" context "Password reset primary action" %}
</button>
- <img class="lazyload" data-src="{% static "images/reset-bg.png" %}" />
+ <img class="lazyload lazypreload" data-src="{% static "images/reset-bg.png" %}" />
</div>
</div>
</form>
diff --git a/templates/account/password_reset_done.html b/templates/account/password_reset_done.html
index c9d9576b05..e9bb6bd703 100644
--- a/templates/account/password_reset_done.html
+++ b/templates/account/password_reset_done.html
@@ -16,7 +16,7 @@
Please contact us if you do not receive it within a few minutes.
{% endblocktrans %}</p>
<div class="row login__btn-group">
- <img class="lazyload" data-src="{% static "images/reset-bg.png" %}" />
+ <img class="lazyload lazypreload" data-src="{% static "images/reset-bg.png" %}" />
</div>
</div>
{% endblock %}
diff --git a/templates/account/password_reset_from_key.html b/templates/account/password_reset_from_key.html
index b05d820854..a94fe9e9bf 100644
--- a/templates/account/password_reset_from_key.html
+++ b/templates/account/password_reset_from_key.html
@@ -31,7 +31,7 @@
<button class="btn primary narrow">
{% trans "Continue" context "Password reset from key form primary action" %}
</button>
- <img class="lazyload" data-src="{% static "images/reset-bg.png" %}" />
+ <img class="lazyload lazypreload" data-src="{% static "images/reset-bg.png" %}" />
</div>
</div>
</form>
diff --git a/templates/account/signup.html b/templates/account/signup.html
index 82b0524789..ccb69031d1 100644
--- a/templates/account/signup.html
+++ b/templates/account/signup.html
@@ -15,7 +15,7 @@
<div class="col-md-6 login__register">
<div class="login__register-link">
<h3>{% trans "Already have an account?" context "Signup form secondary title" %}</h3>
- <img class="signup-img lazyload" data-src="{% static 'images/login-bg.png' %}"
+ <img class="signup-img lazyload lazypreload" data-src="{% static 'images/login-bg.png' %}"
srcset="{% static 'images/login-bg.png' %} 1x, {% static 'images/login-bg2x.png' %} 2x">
<p><a rel="nofollow" href="{% url 'account_login' %}" class="btn secondary narrow">
{% trans "Log in" context "Signup form secondary action" %}
diff --git a/templates/cart/index.html b/templates/cart/index.html
index defe738e72..5ea311c914 100644
--- a/templates/cart/index.html
+++ b/templates/cart/index.html
@@ -42,7 +42,7 @@
<div class="row">
<div class="col-7 cart__line__product">
<a class="link--clean" href="{{ line.variant.get_absolute_url }}">
- <img class="lazyload" data-src="{% get_thumbnail line.variant.product.images.first.image method="crop" size="60x60" %}"
+ <img class="lazyload lazypreload" data-src="{% get_thumbnail line.variant.product.images.first.image method="crop" size="60x60" %}"
data-srcset="{% get_thumbnail line.variant.product.images.first.image method="crop" size="60x60" %} 1x, {% get_thumbnail line.variant.product.images.first.image method="crop" size="120x120" %} 2x"
alt="">
<p>{{ line.variant.product }}<br><small>{{ line.variant }}</small></p>
@@ -82,7 +82,7 @@
</div>
{% else %}
<div class="cart__empty">
- <img class="lazyload" data-src="{% static 'images/empty-cart-bg.png' %}" data-srcset="{% static 'images/empty-cart-bg.png' %} 1x, {% static 'images/empty-cart-bg2x.png' %} 2x">
+ <img class="lazyload lazypreload" data-src="{% static 'images/empty-cart-bg.png' %}" data-srcset="{% static 'images/empty-cart-bg.png' %} 1x, {% static 'images/empty-cart-bg2x.png' %} 2x">
<h2>{% trans "There are no products in your shopping cart." context "Empty cart message" %}</h2>
<a href="{% url 'home' %}" class="btn primary">{% trans "Check out our sales" context "Empty cart link" %}</a>
</div>
diff --git a/templates/cart_dropdown.html b/templates/cart_dropdown.html
index 9ffceb07c0..6abb15d199 100644
--- a/templates/cart_dropdown.html
+++ b/templates/cart_dropdown.html
@@ -11,7 +11,7 @@
<div class="row item">
<div class="col-md-10">
<a class="link--clean" href="{{ line.variant_url }}">
- <img class="cart-dropdown__image lazyload"
+ <img class="cart-dropdown__image lazyload lazypreload"
data-src="{% get_thumbnail line.image size="60x60" %}"
data-srcset="{% get_thumbnail line.image size="60x60" %} 1x, {% get_thumbnail line.image size="120x120" %} 2x"
alt=""
@@ -58,7 +58,7 @@
<img data-src="{% static 'images/empty-cart-bg.png' %}"
data-srcset="{% static 'images/empty-cart-bg.png' %} 1x, {% static 'images/empty-cart-bg2x.png' %} 2x"
src="{% placeholder size=255 %}"
- class="lazyload">
+ class="lazyload lazypreload">
<a href="{% url 'home' %}" class="btn primary">{% trans "Check out our sales" context "Empty cart link" %}</a>
</div>
{% endif %}
diff --git a/templates/category/_items.html b/templates/category/_items.html
index 0847903566..eaaf9784ed 100644
--- a/templates/category/_items.html
+++ b/templates/category/_items.html
@@ -10,7 +10,7 @@
<a href="{{ product.get_absolute_url }}" class="link--clean">
<div class="text-center">
<div>
- <img class="img-responsive lazyload"
+ <img class="img-responsive lazyload lazypreload"
data-src="{% product_first_image product method="crop" size="255x255" %}"
data-srcset="{% product_first_image product method="crop" size="255x255" %} 1x, {% product_first_image product method="crop" size="510x510" %} 2x"
alt=""
diff --git a/templates/category/index.html b/templates/category/index.html
index 1d2fc87eb6..8b30257fd8 100644
--- a/templates/category/index.html
+++ b/templates/category/index.html
@@ -99,13 +99,13 @@
<a href="{% get_sort_by_url choice %}">
<span>{% trans 'ascending' context 'sort by option' %}</span>
<div class="sort-order-icon float-right">
- <img class="lazyload" data-src="{% static "images/arrow-up.svg" %}">
+ <img class="lazyload lazypreload" data-src="{% static "images/arrow-up.svg" %}">
</div>
</a>
<a href="{% get_sort_by_url choice descending=True %}">
<span>{% trans 'descending' context 'sort by option' %}</span>
<div class="sort-order-icon float-right">
- <img class="lazyload" data-src="{% static "images/arrow-down.svg" %}">
+ <img class="lazyload lazypreload" data-src="{% static "images/arrow-down.svg" %}">
</div>
</a>
</div>
@@ -160,7 +160,7 @@
<h3 class="filter-label">
{{ field.label }}
<div class="collapse-filters-icon">
- <img class="lazyload" data-src="{% static "images/chevron-up.svg" %}">
+ <img class="lazyload lazypreload" data-src="{% static "images/chevron-up.svg" %}">
</div>
</h3>
<div class="filter-form-field" style="display:block">
@@ -179,7 +179,7 @@
<h3 class="filter-label">
{{ field.label }}
<div class="collapse-filters-icon">
- <img class="lazyload" data-src="{% static "images/chevron-up.svg" %}">
+ <img class="lazyload lazypreload" data-src="{% static "images/chevron-up.svg" %}">
</div>
</h3>
<div class="filter-form-field" style="display:block">
diff --git a/templates/checkout/login.html b/templates/checkout/login.html
index 67658a6135..d148e8f6b6 100644
--- a/templates/checkout/login.html
+++ b/templates/checkout/login.html
@@ -10,7 +10,7 @@
<div class="col-12 col-md-6">
<div class="checkout__login__continue">
<h3>{% trans "New customer?" context "Checkout login page title" %}</h3>
- <img class="checkout-pirate lazyload"
+ <img class="checkout-pirate lazyload lazypreload"
data-src="{% static 'images/login-bg.png' %}"
data-srcset="{% static 'images/login-bg.png' %} 1x, {% static 'images/login-bg2x.png' %} 2x">
<p>
diff --git a/templates/order/_ordered_items_table.html b/templates/order/_ordered_items_table.html
index 16ef03aae1..49a785fb13 100644
--- a/templates/order/_ordered_items_table.html
+++ b/templates/order/_ordered_items_table.html
@@ -55,7 +55,7 @@
<a class="link--clean" href="{% if item_line.product %}{{ item_line.product.get_absolute_url }}{% endif %}">
<img data-src="{% product_first_image item_line.product size="60x60" method="crop" %}"
data-srcset="{% product_first_image item_line.product size="60x60" method="crop" %} 1x, {% product_first_image item_line.product size="120x120" method="crop" %} 2x"
- class="float-left lazyload"
+ class="float-left lazyload lazypreload"
src="{% placeholder size=60 %}">
<span class="order-details__product__description">{{ item_line.product_name }}</span>
</a>
diff --git a/templates/order/checkout_success.html b/templates/order/checkout_success.html
index e1b31a24a2..2c2b05097c 100644
--- a/templates/order/checkout_success.html
+++ b/templates/order/checkout_success.html
@@ -11,7 +11,7 @@
{% block content %}
<div class="row checkout__thankyoupage">
<div class="col-xl-10 m-auto">
- <img class="checkout__thankyoupage__parrot lazyload" data-src="{% static 'images/confirm-order-bg.png' %}"
+ <img class="checkout__thankyoupage__parrot lazyload lazypreload" data-src="{% static 'images/confirm-order-bg.png' %}"
srcset="{% static 'images/confirm-order-bg.png' %} 1x, {% static 'images/confirm-order-bg2x.png' %} 2x">
<h1>{% blocktrans trimmed with order_url=order.get_absolute_url context "Checkout title" %}
Thank you for your <a href="{{ order_url }}">order</a>!
@@ -23,7 +23,7 @@
{% endblocktrans %}</p>
</div>
<div class="m-auto">
- <img class="checkout-pirate lazyload" data-src="{% static 'images/checkout-bg.png' %}"
+ <img class="checkout-pirate lazyload lazypreload" data-src="{% static 'images/checkout-bg.png' %}"
srcset="{% static 'images/checkout-bg.png' %} 1x, {% static 'images/checkout-bg2x.png' %} 2x">
<p><a href="{% url 'home' %}" class="btn secondary">
{% trans "Continue shopping" context "Checkout secondary action" %}
diff --git a/templates/order/checkout_success_anonymous.html b/templates/order/checkout_success_anonymous.html
index 5f2929f5cb..02daa021d0 100644
--- a/templates/order/checkout_success_anonymous.html
+++ b/templates/order/checkout_success_anonymous.html
@@ -11,7 +11,7 @@
{% block content %}
<div class="row checkout__thankyoupage">
<div class="col-xl-10 m-auto">
- <img class="checkout__thankyoupage__parrot lazyload" data-src="{% static 'images/confirm-order-bg.png' %}"
+ <img class="checkout__thankyoupage__parrot lazyload lazypreload" data-src="{% static 'images/confirm-order-bg.png' %}"
data-srcset="{% static 'images/confirm-order-bg.png' %} 1x, {% static 'images/confirm-order-bg2x.png' %} 2x">
<h1>{% blocktrans trimmed with order_url=order.get_absolute_url context "Checkout title" %}
Thank you for your <a href="{{ order_url }}">order</a>!
@@ -52,7 +52,7 @@
{% endif %}
</div>
<div class="col-md-6 pull-md-6">
- <img class="checkout-pirate lazyload" data-src="{% static 'images/checkout-bg.png' %}"
+ <img class="checkout-pirate lazyload lazypreload" data-src="{% static 'images/checkout-bg.png' %}"
data-srcset="{% static 'images/checkout-bg.png' %} 1x, {% static 'images/checkout-bg2x.png' %} 2x">
<p><a href="{% url 'home' %}" class="btn secondary">
{% trans "Continue shopping" context "Checkout secondary action" %}
diff --git a/templates/product/details.html b/templates/product/details.html
index c0a4b14851..acc088c1d9 100644
--- a/templates/product/details.html
+++ b/templates/product/details.html
@@ -68,7 +68,7 @@
<div class="carousel-inner" role="listbox">
{% for image in images %}
<div class="carousel-item{% if forloop.first %} active{% endif %}">
- <img class="d-block img-fluid lazyload"
+ <img class="d-block img-fluid lazyload lazypreload"
data-src="{% get_thumbnail image.image method="crop" size="540x540" %}"
data-srcset="{% get_thumbnail image.image method="crop" size="540x540" %} 1x, {% get_thumbnail image.image method="crop" size="1080x1080" %} 2x"
alt=""
@@ -91,7 +91,7 @@
<img data-src="{% get_thumbnail image.image method="crop" size="60x60" %}"
data-srcset="{% get_thumbnail image.image method="crop" size="60x60" %} 1x, {% get_thumbnail image.image method="crop" size="120x120" %} 2x"
alt=""
- class="lazyload"
+ class="lazyload lazypreload"
src="{% placeholder size=60 %}">
</li>
{% endif %}
@@ -102,7 +102,7 @@
<img data-src="{% placeholder size=540 %}"
data-srcset="{% placeholder size=540 %} 1x, {% placeholder size=1080 %} 2x"
alt=""
- class="img-fluid lazyload">
+ class="img-fluid lazyload lazypreload">
{% endif %}
{% endwith %}
</div>