What is SSR?
SSR, or Server-Side-Rendering, is a mechanism and set of conventions where an application or content is rendered with minimal work from the client.
With SSR, the client does not execute JavaScript. Instead, the client renders HTML/CSS which was "rendered" by the server.
Benefits of SSR
A major benefit of SSR is that JavaScript is not required. Because of this, applications can be built to feel "lighter" in many use cases.
Additionally, SSR can be used as a fallback in the event that the user has JavaScript disabled. This way comment threads can still render, and the user can still reply to comments.
FastComments is already well optimized, so in most cases SSR is not required. However, some online communities have users which do not use JavaScript, or disabling it is the preferred practice. This is where FastComments SSR can be useful.
However, a major trade-off of SSR is having to reload the page for small state changes.
FastComments SSR Supported Features
FastComments supports the following features with SSR:
- Customizable commenting widget.
- Anonymous commenting.
- Commenting while logged in.
- SSO.
- Root and nested replies.
- Viewing & paginating comment threads.
- Voting, including anonymous voting.
- Changing the default sort direction.
An Example
An example of FastComments SSR is available here.
Use Cases
Example use cases of SSR are as follows:
- A fallback for when JavaScript is disabled.
- To render a comment interface in an environment where JavaScript is not available or desired.
- For sites or online communities where the inclusion of more JavaScript is not desired.
Where FastComments Uses SSR
FastComments uses SSR in the following places:
- Our WordPress plugin uses SSR as a fallback by default. If JavaScript is disabled, users can still comment on your blog.
- We use it as a fallback on our own Blog! https://blog.fastcomments.com
Using SSR
To use FastComments SSR, the client may fetch HTML from the https://fastcomments.com/ssr/comments
endpoint.
This can be done a number of ways.
With WordPress
SSR is enabled by default for users without JS enabled as a fallback in the WordPress plugin since version 3.10.2
.
In a Webpage
With an already existing application, SSR can be added with the following example, assuming the language used is PHP:
We can also only show the SSR UI when the user has JS disabled:
For an example using SSO, see here.
With Pre-Rendered Content
Our blog is generated at build time, and provides a good example of SSR with Handlebars.
The Basic Parameters
The basic parameters that you need to pass are:
tenantId
- This identifies you as a customer.urlId
- This identifies the page or article to load comments for, and defines where they are saved.url
- This is used for notifications and related features to link back to the comment thread.
Custom Styling
The SSR version of the comment widget uses the same structure and rendering engine as the JavaScript one.
As such, all custom styling that works for the JavaScript commenting widget works for SSR.
Notes
With SSR, there is no JavaScript to control the height of the rendered container. In browsers, a vertical scrollbar may show for long discussions.
As such, you must tune this as desired.