In one of my projects I needed to layout photos in a grid that will place all photos most effectively with no white spaces between them. The prolem is that photos can have various sizes and proportions.
In this case I used Masonry with:
– imagesLoaded to have callback when all images are loaded on a page
– Unveil to lazy load images when they become visible on page
So sometimes it is a bit tricky, and its drawbacks may be observed – sometimes Masonry unfortunately does not layout items well. But it is quite hard to replicate, so I can recommend Masonry.