Using Discourse as commenting system via JavaScript: Delay load or load on scroll

As mentioned above, I use discourse as the commenting system and here’s an example

Quite a few users upload images to the comments and the JS itself is impacting the load time.

Is there a way I can load the commenting system only on scroll? Which if you think about it makes sense – you need to load it only on user intent – when to read comments.


This is the code I use

<div id="comments" class="ct-post-end-section">
	<div id='discourse-comments'></div>
	<script type="text/javascript">
	  DiscourseEmbed = { discourseUrl: '',
                     discourseEmbedUrl: '<?php echo get_permalink(); ?>' };
	  (function() {
	    var d = document.createElement('script'); d.type = 'text/javascript'; d.async = true;
	    d.src = DiscourseEmbed.discourseUrl + 'javascripts/embed.js';
	    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(d);
</div><!-- #comments -->

Wonder if it’s the right approach to attach the script to onscroll? Although I understand complexities between repeated scroll events firing.

Look for a plugin named “lazy load” on your blog. that’ll only load images when it actually enters the viewport of the reader.

I don’t do lady load on the blog posts due to SEO reasons. Hit me hard some time back. Nevertheless, a lazy load plugin is not going to do anything to the commenting system (which is in an IFRAME).

1 Like

Right. an iframe won’t be affected by lazy load. my bad. maybe developers can help you out.

But I don’t get this. How lazy load affected SEO?

Crawlers look for HTML code and tags. images load only after entering the viewport, but the code is always available after first load.

That Discourse lazy load might be more relevant:

In theory what you are saying is right. But Google works in mysterious ways.

1 Like

I don’t think that’d help on the blog as well.

There needs to be a lazy loading option within the discourse comments plugin itself, if that’s what she is asking for

1 Like