Lazy loading
Hi! I want to use https://github.com/aFarkas/lazysizes or https://github.com/tuupola/jquery_lazyload. But I want do it on the fly in server side, while post saving. I think it will be much more useful, then doing it by hands, while editing the post.
Can somebody help me? Ghost is enough big project. And try to understand all principals of working system is difficult for noobie. Can somebody suggest me the study area? Is it a server/helpers?
Hi @Pestov
Thanks for dropping by! From what I understand, both those scripts require non-standard image markup like this.
<img alt="" class="lazy" src="blank.gif" data-original="img/example.jpg" width="640" height="480">
Unfortunately, at this time I don't think it will be very straightforward to configure the markdown compiler to output that, instead of the standard image markup. This may be possible with an app at some point in the future. Remember though for now, you can always include normal HTML in your markdown files so you have the option of adding this special markup to your posts manually.
I don't know what your requirements are, but I'm not sure that lazy loading images is even considered to be good practice in most cases. Images don't actually block anything before they load. In a sense, they are already lazy loaded by the browser. The onload event notifies you that all of the content including images has been downloaded, but that is long after the document is ready.
Images do hog HTTP connections though which are limited by the browser to two per domain at a time I believe. But you can easily overcome this limitation with a CDN. I'd recommend using a free Cloudflare account or something like that which should speed up the loading of images significantly.
What @joeldrapper wrote above is probably good guidance. If you're still interested in working on integrating a library like that, I suspect you'll have to work with the theme helpers, which are located in core/server/helpers/.
@joeldrapper big thanks for so informative reply. But for example my blog posts are useally looks like this http://ipestov.com/awesomeness-and-usefulness-for-web-developers-15/, with a lot numbers of images. I want to automate the adding 'lazy' class for all images. And I want to do it just not because I am a lazy =), I like clean .md content for my posts. So, I will trying do it on server side.
@jaswilli thanks for help