Skip to content

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

Add image lazy loading

dominik-zeglen3c603c63a51b
diff --git a/package-lock.json b/package-lock.json
index 1bfae68732..261410eb90 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -6374,6 +6374,11 @@
"resolved": "https://registry.npmjs.org/lazy-cache/-/lazy-cache-1.0.4.tgz",
"integrity": "sha1-odePw6UEdMuAhF07O24dpJpEbo4="
},
+ "lazysizes": {
+ "version": "4.0.1",
+ "resolved": "https://registry.npmjs.org/lazysizes/-/lazysizes-4.0.1.tgz",
+ "integrity": "sha1-Qo/pVh1/9cOysnh7eO1UCAmGQgs="
+ },
"lcid": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/lcid/-/lcid-1.0.0.tgz",
diff --git a/package.json b/package.json
index 0926fbf995..8420978457 100644
--- a/package.json
+++ b/package.json
@@ -24,6 +24,7 @@
"favicons-webpack-plugin": "^0.0.7",
"jquery": "^3.1.1",
"jquery.cookie": "^1.4.1",
+ "lazysizes": "^4.0.1",
"materialize-css": "^0.100.2",
"medium-editor": "^5.23.3",
"mobx": "^3.0.2",
@@ -85,8 +86,8 @@
}
},
"scripts": {
- "build-assets": "node ./node_modules/webpack/bin/webpack.js -p",
+ "build-assets": "node ./node_modules/webpack/bin/webpack.js -p --progress",
"heroku-postbuild": "npm run build-assets",
- "start": "UV_THREADPOOL_SIZE=8 node ./node_modules/webpack/bin/webpack.js -d --watch"
+ "start": "UV_THREADPOOL_SIZE=8 node ./node_modules/webpack/bin/webpack.js -d --watch --progress"
}
}
diff --git a/saleor/static/js/components/misc.js b/saleor/static/js/components/misc.js
index 326af66961..1a9495e245 100644
--- a/saleor/static/js/components/misc.js
+++ b/saleor/static/js/components/misc.js
@@ -1,3 +1,4 @@
+import 'lazysizes';
import SVGInjector from 'svg-injector-2';
export const getAjaxError = (response) => {
diff --git a/templates/account/login.html b/templates/account/login.html
index b8b68a2edc..5d598297cd 100644
--- a/templates/account/login.html
+++ b/templates/account/login.html
@@ -14,8 +14,9 @@
<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 src="{% static 'images/login-bg.png' %}"
- srcset="{% static 'images/login-bg.png' %} 1x, {% static 'images/login-bg2x.png' %} 2x">
+ <img class="lazyload"
+ 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">
{% trans "Register" context "Login form secondary action" %}
</a>
diff --git a/templates/account/password_reset.html b/templates/account/password_reset.html
index 82de745642..526ccdf7a5 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 src="{% static "images/reset-bg.png" %}" />
+ <img class="lazyload" 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 dfe24bf1ed..c9d9576b05 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 src="{% static "images/reset-bg.png" %}" />
+ <img class="lazyload" 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 b66bc98ae8..b05d820854 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 src="{% static "images/reset-bg.png" %}" />
+ <img class="lazyload" data-src="{% static "images/reset-bg.png" %}" />
</div>
</div>
</form>
diff --git a/templates/account/signup.html b/templates/account/signup.html
index 964a307fd9..82b0524789 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" src="{% static 'images/login-bg.png' %}"
+ <img class="signup-img lazyload" 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/base.html b/templates/base.html
index 1e9a9dd718..5e7010dc02 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -11,13 +11,13 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="{% block meta_description %}{% endblock %}">
<meta name="author" content="{% trans "Mirumee Software" context "Meta author text" %}">
- <meta name="theme-color" content="#21915a">
+ <meta name="theme-color" content="#333333">
<meta name="og:type" content="website">
{% endblock meta %}
{% include 'favicon.html' %}
- {% render_bundle 'vendor' 'css' %}
- {% render_bundle 'storefront' 'css' %}
+ {% render_bundle 'vendor' 'css' attrs='async' %}
+ {% render_bundle 'storefront' 'css' attrs='async' %}
{% block stylesheet %}{% endblock stylesheet %}
@@ -27,6 +27,8 @@
<meta property="og:image" content="{% static "images/block1.png" %}">
{% endblock meta_tags %}
+ <link rel="manifest" href="./manifest.json">
+
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
diff --git a/templates/cart/index.html b/templates/cart/index.html
index 533bba9dd4..defe738e72 100644
--- a/templates/cart/index.html
+++ b/templates/cart/index.html
@@ -42,9 +42,9 @@
<div class="row">
<div class="col-7 cart__line__product">
<a class="link--clean" href="{{ line.variant.get_absolute_url }}">
- <img src="{% get_thumbnail line.variant.product.images.first.image method="crop" size="60x60" %}"
- 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="">
+ <img class="lazyload" 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>
</a>
</div>
@@ -82,7 +82,7 @@
</div>
{% else %}
<div class="cart__empty">
- <img src="{% static 'images/empty-cart-bg.png' %}" srcset="{% static 'images/empty-cart-bg.png' %} 1x, {% static 'images/empty-cart-bg2x.png' %} 2x">
+ <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">
<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 8a6a1a6013..c1a2cd068b 100644
--- a/templates/cart_dropdown.html
+++ b/templates/cart_dropdown.html
@@ -10,8 +10,9 @@
<div class="row item">
<div class="col-md-10">
<a class="link--clean" href="{{ line.variant_url }}">
- <img class="cart-dropdown__image" src="{% get_thumbnail line.image size="60x60" %}"
- srcset="{% get_thumbnail line.image size="60x60" %} 1x, {% get_thumbnail line.image size="120x120" %} 2x"
+ <img class="cart-dropdown__image lazyload"
+ 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="">
<h3>
{{ line.product }}
diff --git a/templates/category/_items.html b/templates/category/_items.html
index 549d6ac251..df7998a742 100644
--- a/templates/category/_items.html
+++ b/templates/category/_items.html
@@ -9,9 +9,9 @@
<a href="{{ product.get_absolute_url }}" class="link--clean">
<div class="text-center">
<div>
- <img class="img-responsive"
- src="{% product_first_image product method="crop" size="255x255" %}"
- srcset="{% product_first_image product method="crop" size="255x255" %} 1x, {% product_first_image product method="crop" size="510x510" %} 2x"
+ <img class="img-responsive lazyload"
+ 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="">
<span class="product-list-item-name" title="{{ product }}">{{ product }}</span>
</div>
diff --git a/templates/category/index.html b/templates/category/index.html
index f578baff0b..a531be4d41 100644
--- a/templates/category/index.html
+++ b/templates/category/index.html
@@ -98,13 +98,13 @@
<a href="{% get_sort_by_url choice %}">
<span>{% trans 'ascending' context 'sort by option' %}</span>
<div class="sort-order-icon float-right">
- <img src="{% static "images/arrow-up.svg" %}">
+ <img class="lazyload" 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 src="{% static "images/arrow-down.svg" %}">
+ <img class="lazyload" data-src="{% static "images/arrow-down.svg" %}">
</div>
</a>
</div>
@@ -159,7 +159,7 @@
<h3 class="filter-label">
{{ field.label }}
<div class="collapse-filters-icon">
- <img src="{% static "images/chevron-up.svg" %}">
+ <img class="lazyload" data-src="{% static "images/chevron-up.svg" %}">
</div>
</h3>
<div class="filter-form-field" style="display:block">
@@ -178,7 +178,7 @@
<h3 class="filter-label">
{{ field.label }}
<div class="collapse-filters-icon">
- <img src="{% static "images/chevron-up.svg" %}">
+ <img class="lazyload" 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 7c6f352059..3908d03f5f 100644
--- a/templates/checkout/login.html
+++ b/templates/checkout/login.html
@@ -9,7 +9,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" src="{% static 'images/login-bg.png' %}" srcset="{% static 'images/login-bg.png' %} 1x, {% static 'images/login-bg2x.png' %} 2x">
+ <img class="checkout-pirate lazyload" data-src="{% static 'images/login-bg.png' %}" data-srcset="{% static 'images/login-bg.png' %} 1x, {% static 'images/login-bg2x.png' %} 2x">
<p>
<a href="{% url 'checkout:index' %}" class="btn secondary narrow">
{% trans "Continue" context "Checkout login page new users action" %}
diff --git a/templates/favicon.html b/templates/favicon.html
index fff5f4bd02..87d79c41e4 100644
--- a/templates/favicon.html
+++ b/templates/favicon.html
@@ -1,7 +1,7 @@
{% load webpack_static from webpack_loader %}
<meta name="mobile-web-app-capable" content="yes">
-<meta name="application-name" content="favicons-webpack-plugin">
+<meta name="application-name" content="{{ site.name }}">
<link rel="apple-touch-icon" sizes="57x57" href="{% webpack_static "favicons/apple-touch-icon-57x57.png" %}">
<link rel="apple-touch-icon" sizes="60x60" href="{% webpack_static "favicons/apple-touch-icon-60x60.png" %}">
<link rel="apple-touch-icon" sizes="72x72" href="{% webpack_static "favicons/apple-touch-icon-72x72.png" %}">
diff --git a/templates/order/_ordered_items_table.html b/templates/order/_ordered_items_table.html
index 3f1b60f76e..8327b303fa 100644
--- a/templates/order/_ordered_items_table.html
+++ b/templates/order/_ordered_items_table.html
@@ -52,9 +52,9 @@
<div class="row">
<div class="col-md-6 col-9">
<a class="link--clean" href="{% if item_line.product %}{{ item_line.product.get_absolute_url }}{% endif %}">
- <img src="{% product_first_image item_line.product size="60x60" method="crop" %}"
- 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">
+ <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">
<span class="order-details__product__description">{{ item_line.product_name }}</span>
</a>
</div>
diff --git a/templates/order/checkout_success.html b/templates/order/checkout_success.html
index a0984c48f2..4d455fa629 100644
--- a/templates/order/checkout_success.html
+++ b/templates/order/checkout_success.html
@@ -10,7 +10,7 @@
{% block content %}
<div class="row checkout__thankyoupage">
<div class="col-xl-10 m-auto">
- <img class="checkout__thankyoupage__parrot" src="{% static 'images/confirm-order-bg.png' %}"
+ <img class="checkout__thankyoupage__parrot lazyload" 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>!
@@ -22,7 +22,7 @@
{% endblocktrans %}</p>
</div>
<div class="m-auto">
- <img class="checkout-pirate" src="{% static 'images/checkout-bg.png' %}"
+ <img class="checkout-pirate lazyload" 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 3edfab8f44..f63a52ac38 100644
--- a/templates/order/checkout_success_anonymous.html
+++ b/templates/order/checkout_success_anonymous.html
@@ -10,8 +10,8 @@
{% block content %}
<div class="row checkout__thankyoupage">
<div class="col-xl-10 m-auto">
- <img class="checkout__thankyoupage__parrot" src="{% static 'images/confirm-order-bg.png' %}"
- srcset="{% static 'images/confirm-order-bg.png' %} 1x, {% static 'images/confirm-order-bg2x.png' %} 2x">
+ <img class="checkout__thankyoupage__parrot lazyload" 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>!
{% endblocktrans %}</h1>
@@ -51,8 +51,8 @@
{% endif %}
</div>
<div class="col-md-6 pull-md-6">
- <img class="checkout-pirate" src="{% static 'images/checkout-bg.png' %}"
- srcset="{% static 'images/checkout-bg.png' %} 1x, {% static 'images/checkout-bg2x.png' %} 2x">
+ <img class="checkout-pirate lazyload" 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" %}
</a></p>
diff --git a/templates/product/details.html b/templates/product/details.html
index b8f20e3621..7d9fc37801 100644
--- a/templates/product/details.html
+++ b/templates/product/details.html
@@ -67,9 +67,9 @@
<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"
- src="{% get_thumbnail image.image method="crop" size="540x540" %}"
- srcset="{% get_thumbnail image.image method="crop" size="540x540" %} 1x, {% get_thumbnail image.image method="crop" size="1080x1080" %} 2x" alt="">
+ <img class="d-block img-fluid lazyload"
+ 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="">
</div>
{% endfor %}
</div>
@@ -85,19 +85,20 @@
{% for image in images %}
{% if images|length > 1 %}
<li data-target="#carousel-example-generic" data-slide-to="{{ forloop.counter0 }}"{% if forloop.first %} class="active"{% endif %}>
- <img src="{% get_thumbnail image.image method="crop" size="60x60" %}"
- srcset="{% get_thumbnail image.image method="crop" size="60x60" %} 1x, {% get_thumbnail image.image method="crop" size="120x120" %} 2x"
- alt="">
+ <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">
</li>
{% endif %}
{% endfor %}
</ol>
</div>
{% else %}
- <img src="{% static 'images/placeholder540x540.png' %}"
- srcset="{% static 'images/placeholder540x540.png' %} 1x, {% static 'images/placeholder1080x1080.png' %} 2x"
+ <img data-src="{% static 'images/placeholder540x540.png' %}"
+ data-srcset="{% static 'images/placeholder540x540.png' %} 1x, {% static 'images/placeholder1080x1080.png' %} 2x"
alt=""
- class="img-fluid">
+ class="img-fluid lazyload">
{% endif %}
{% endwith %}
</div>