You forgot to use $(document).ready() . Read here why you should use this .
In particular, if you want to make absolutely sure that the images are uploaded, you can use:
$(window).load(function () { $('.main-gallery').flickity({ wrapAround: true, freeScroll: true, lazyLoad: 3 }); });
This is because $(window).load() will only execute when the DOM and all images load.
Alternatively, you can use the lazyLoad parameter to make sure that images in neighboring cells are loaded. For proper operation, make sure that the slider has more images than the page width. In this case, everything should work fine.
source share