Embedding Discourse Comments *without* Javascript

AI-generated summary

The discussion is about embedding Discourse comments without using JavaScript. deeplow shares a method using a simple iframe to embed comments, which they found to work without any issues. However, eviltrout notes that this method is not officially supported and that the JavaScript-based embedding is more powerful due to its ability to handle automatic sizing and scrolling. eviltrout clarifies that the JavaScript is not just for aesthetics, but provides a more robust solution. deeplow asks for an example of how the JavaScript-based embedding differs from the iframe method, but eviltrout emphasizes that the iframe method is unsupported, although it may still work for specific use cases.

There is this great post on how to Embed Discourse comments on another website via Javascript. However, there are communities where website visitors may not be running javascript. And if not for that, I would argue from the SEO perspective that there should be a way to embed site comments without javascript.

After paying a bit around I find that it can be easily implemented in a much simpler way without any javascript. It’s just a matter of following:

<iframe id="discourse-embed-frame" scrolling="no" referrerpolicy="no-referrer-when-downgrade" 
src="https://<DISCOURSE_URL>/embed/comments/?embed_url=<WEBSITE_PAGE_URL>%2F&amp;discourse_username=system" 
width="100%" height="3271px" frameborder="0"></iframe>

For example:

<iframe src="https://meta.discourse.org/embed/comments?embed_url=https%3A%2F%2Fblog.discourse.org%2F2021%2F05%2Fdiscord-and-discourse-better-together%2F&amp;discourse_username=rishabh" 
id="discourse-embed-frame" scrolling="no" referrerpolicy="no-referrer-when-downgrade"
width="100%" height="3271px" frameborder="0"></iframe>

Is there any reason why wouldn’t work?

It’s a myth that modern search engines can’t execute Javascript. The embedding is much more powerful because of the Javascript usage and there are no plans to add an alternative at this time. You are free to use Discourse’s APIs to retrieve the same content server side and render it that way.

I see. However, from my little testing the above mentioned method does work without any changes. My question stemmed from possible edge-cases where it could break and that I was not thinking about.

Yes, that would be the other route.

Can you provide an example? I fail to see how they differ if the end result is the same iframe.

The Javascript is not doing nothing. It’s used for automatic sizing and scrolling. It also provides an easier API by looking for optional parameters.

It is the only supported way of doing this. If you find the <iframe> works for your purposes you can use it in an unsupported way.