6

This issue is very similar to the following issue, but this goes a little bit further. Cache tag won’t cache in a template

I have a page which is made up of hundreds of lazy loaded images similarly to this:

 <img data-original="{{ image.getUrl(transform) }}" src="/img/placeholder.png" alt="" />

The page takes anywhere between 2 and 5 seconds to load, and yet the server isn't under powered in any way.

The majority of the images on the page aren't transformed within a few page loads. It's quite possible that there are images that no one will ever look at, therefore will never be transformed... Craft will hold off on caching until all the images are transformed; which might never happen.

I could duplicate the template, and turn off lazy loading, and get my client to load that page every time they make changes, but I would prefer not having to ask my client to anything like that.

Apart from loading stuff via ajax when needed, does anyone know of an easy way to get all the images transformed or to get caching working so that it doesn't require all assets to be transformed?

1 Answer 1

7

Set generateTransformsBeforePageLoad in your config/general.php file.

'generateTransformsBeforePageLoad' => true,

Configures Craft to generate new image transforms right when getUrl() is called, rather than when the browser first requests the image.

1
  • Oh, I should have seen that setting earlier! Thanks Marion for the answer; this is perfect. Mar 18, 2015 at 8:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.