Skip to content

Commit 81c11d3

Browse files
JS-339: [SwatchRenderer.js] Preload images for all available options
1 parent 61a65f0 commit 81c11d3

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

app/code/Magento/Swatches/view/frontend/web/js/SwatchRenderer.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* See COPYING.txt for license details.
44
*/
55

6-
define(['jquery', 'underscore', 'jquery/ui'], function ($, _) {
6+
define(['jquery', 'underscore', 'mage/gallery/preloadImages', 'jquery/ui'], function ($, _, preloadImages) {
77
'use strict';
88

99
/**
@@ -218,6 +218,27 @@ define(['jquery', 'underscore', 'jquery/ui'], function ($, _) {
218218
'img': $main.find('.product-image-photo').attr('src')
219219
}];
220220
}
221+
this._preloadSwatchesImages();
222+
},
223+
224+
/**
225+
* Preloads optional configuration images.
226+
* @private
227+
*/
228+
_preloadSwatchesImages: function () {
229+
var options = this.options;
230+
231+
_.each(options.jsonConfig.images, function (array) {
232+
var fullImagesList = [],
233+
imagesList = [];
234+
235+
_.each(array, function (item) {
236+
imagesList.push(item.img);
237+
fullImagesList.push(item.full);
238+
});
239+
preloadImages(imagesList);
240+
preloadImages(fullImagesList);
241+
});
221242
},
222243

223244
/**

0 commit comments

Comments
 (0)