Adding a comment section can turn a one-way tutorial into a useful technical discussion. Readers can report outdated instructions, ask implementation questions, and share alternative solutions.
For a static Astro website, however, building your own comments database and authentication system is often more infrastructure than you need.
Giscus offers a different approach: it embeds conversations backed by GitHub Discussions, without requiring you to operate a comments server. In this guide, we’ll configure Giscus, connect it to an Astro article layout, add an explicit Load comments button for privacy-conscious loading, and test the result on Cloudflare Pages.
The key tradeoff: readers must use a GitHub account to participate. This is a reasonable fit for a developer-focused blog, but it may be too restrictive for a general audience.
1. What Is Giscus and How Does It Work?
Giscus is an open-source comments widget built on GitHub Discussions. Each supported page is associated with a discussion in a GitHub repository. Readers can view the conversation and, after authenticating with GitHub, post comments and reactions.
The basic flow is:
Astro article page
|
v
Giscus JavaScript + iframe
|
v
Find discussion by page mapping
|
v
Public GitHub Discussions repository
|
v
Read comments / authenticate / contribute
Giscus doesn’t need a new database inside your Astro project. The comments reside in GitHub Discussions, and maintainers moderate them on GitHub.
A discussion is not necessarily created as soon as a visitor opens the page. According to Giscus, if there is no matching discussion, the bot creates one when somebody first posts a comment or reaction.
That distinction matters when you are estimating how many discussions your repository will contain.
2. Is Giscus a Good Fit for Your Astro Blog?
Giscus is attractive because it minimizes server-side work, supports themes, and provides moderation through familiar GitHub tools. It also creates a public place where technical answers can remain available.
| Factor | Giscus | Custom comments backend |
|---|---|---|
| Data storage | GitHub Discussions | Your database or provider |
| Reader sign-in | GitHub required for posting | Depends on your design |
| Setup | Public repository and embed | Authentication, database, abuse controls |
| Moderation | GitHub moderation tools | You implement or buy moderation |
| Reader reach | Best for developer audiences | Potentially broader |
| Third-party requests | Giscus/GitHub when loaded | Depends on architecture |
| Operational complexity | Relatively low | Often higher |
For a blog about Astro, software engineering and automation, GitHub authentication may be acceptable. For a family blog or an audience without GitHub accounts, an email-based contact form may be a better way to collect feedback.
There is no guaranteed SEO or engagement increase from installing a comment widget. Its value depends on whether readers actually participate and whether conversations remain useful and moderated.

Figure 1. Giscus associates the article with a discussion using a configurable mapping strategy.
3. Prerequisites
You will need:
- An existing Astro blog with a shared article layout.
- A GitHub account that can manage a repository.
- A public repository for comments, with GitHub Discussions enabled.
- Permission to install the Giscus GitHub App on that repository.
- A working local Astro build and a Cloudflare Pages preview environment for testing.
- A chosen strategy for linking article URLs to discussions.
If your website source repository is private, do not make your source code public merely to use Giscus. Create a separate public repository dedicated to discussion threads instead.
Decap CMS is still responsible for the article content. Giscus comments are stored separately in GitHub Discussions; they are not written into Markdown frontmatter or the CMS editorial workflow.
4. Create a Public Discussions Repository
On GitHub, create a public repository, for example:
YOUR_GITHUB_ACCOUNT/blog-discussions
You can keep the Astro source code in another repository. In the new comments repository:
- Open Settings.
- Find the Features section.
- Enable Discussions.
- Create or select a discussion category for article comments.
- Review who can moderate conversations.
Giscus recommends an Announcements-type category for its automatic discussion workflow. This helps restrict creation of new discussion topics while still allowing readers to reply where permitted.
Do not rely on the category name alone as a security control; verify your repository’s actual discussion permissions.
Official setup: Giscus and GitHub Discussions documentation.
5. Install the Giscus App and Obtain Configuration IDs
Visit giscus.app and enter the public repository name in the configuration form.
The tool checks whether the repository is public, whether the Giscus app is installed, and whether Discussions are enabled. Follow the installation link if required.
Once configured, Giscus provides a script with attributes similar to these:
<script src="https://giscus.app/client.js"
data-repo="YOUR_GITHUB_ACCOUNT/blog-discussions"
data-repo-id="YOUR_REAL_REPO_ID"
data-category="Announcements"
data-category-id="YOUR_REAL_CATEGORY_ID"
data-mapping="pathname"
data-strict="1"
data-reactions-enabled="1"
data-emit-metadata="0"
data-input-position="top"
data-theme="preferred_color_scheme"
data-lang="en"
crossorigin="anonymous"
async>
</script>
Do not copy the placeholder IDs into production. The repository and category IDs must come from your own configuration page.
These IDs are configuration identifiers, not API secrets. Still, only grant the Giscus GitHub App the repository permissions it needs.
6. Choose a Stable Page-to-Discussion Mapping
Giscus can match discussions by several signals, including URL, pathname, title, or a specific term.
For many Astro blogs, pathname is a straightforward default:
/blog/my-astro-tutorial/
This is generally more portable between preview and production domains than matching an entire absolute URL. But it introduces a maintenance concern: changing the article slug changes the pathname.
Suppose the page moves from:
/blog/old-astro-guide/
to:
/blog/improved-astro-guide/
A 301 redirect can help readers and search engines reach the new page, but it does not automatically migrate Giscus discussion mapping. You must verify or deliberately update the mapping after a slug change.
For sites where article URLs change often, consider stable, explicit discussion identifiers or another durable mapping strategy, and test the resulting behavior before migration.
data-strict="1" reduces false matches caused by GitHub’s fuzzy discussion search. For older discussion threads, check the advanced Giscus documentation before enabling strict matching, because older threads may not contain the hash used by strict matching.
7. Decide How and When the Widget Loads
The fastest implementation is to paste the supplied Giscus script directly into the article layout. This is simple, but it starts loading a third-party script as the article renders.
For a privacy-conscious technical blog, a more deliberate option is to render a local Load comments button first. Giscus is injected only after the reader clicks that button.
This does three things:
- Avoids an initial request to
giscus.appfrom this component. - Keeps third-party comment JavaScript out of the initial article load.
- Makes the external integration visible to the reader before it starts.
This is a practical design choice, not a blanket guarantee of legal compliance. Your privacy notice and consent requirements still depend on applicable rules and your other website integrations.
Giscus also offers lazy iframe loading, but that is not the same as postponing the external script itself until a click. Our implementation uses both where supported.
8. Build a Reusable GiscusComments.astro Component
Create a component at:
src/components/GiscusComments.astro
The following example defers the external script until a reader clicks. It uses the official Giscus configuration attributes and supports Astro ClientRouter navigation.
---
interface Props {
repo: `${string}/${string}`;
repoId: string;
category: string;
categoryId: string;
}
const { repo, repoId, category, categoryId } = Astro.props;
---
<section
class="comments-shell"
aria-labelledby="comments-heading"
data-giscus-shell
data-repo={repo}
data-repo-id={repoId}
data-category={category}
data-category-id={categoryId}
>
<h2 id="comments-heading">Join the discussion</h2>
<p>
Comments are hosted by GitHub Discussions. Loading them will connect
your browser to giscus.app, and posting requires a GitHub account.
</p>
<button type="button" data-load-giscus>Load comments</button>
<p role="status" data-giscus-status aria-live="polite"></p>
<div class="giscus"></div>
</section>
<script>
function setUpComments(): void {
document.querySelectorAll<HTMLElement>('[data-giscus-shell]').forEach((shell) => {
const button = shell.querySelector<HTMLButtonElement>('[data-load-giscus]');
const status = shell.querySelector<HTMLElement>('[data-giscus-status]');
const mount = shell.querySelector<HTMLElement>('.giscus');
if (!button || !mount || button.dataset.bound === '1') return;
button.dataset.bound = '1';
button.addEventListener('click', () => {
if (shell.dataset.loaded === '1') return;
const { repo, repoId, category, categoryId } = shell.dataset;
if (!repo || !repoId || !category || !categoryId) {
if (status) status.textContent = 'Comments are not configured yet.';
return;
}
shell.dataset.loaded = '1';
button.disabled = true;
if (status) status.textContent = 'Loading comments…';
const script = document.createElement('script');
script.src = 'https://giscus.app/client.js';
script.async = true;
script.crossOrigin = 'anonymous';
const options: Record<string, string> = {
repo,
'repo-id': repoId,
category,
'category-id': categoryId,
mapping: 'pathname',
strict: '1',
'reactions-enabled': '1',
'emit-metadata': '0',
'input-position': 'top',
theme: 'preferred_color_scheme',
lang: 'en',
loading: 'lazy',
};
for (const [key, value] of Object.entries(options)) {
script.setAttribute(`data-${key}`, value);
}
script.addEventListener('load', () => {
button.hidden = true;
if (status) status.textContent = 'Comments script loaded; the discussion may take a moment to appear.';
}, { once: true });
script.addEventListener('error', () => {
shell.dataset.loaded = '0';
button.disabled = false;
if (status) status.textContent = 'Could not load comments. Please try again.';
script.remove();
}, { once: true });
mount.appendChild(script);
});
});
}
document.addEventListener('astro:page-load', setUpComments);
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', setUpComments, { once: true });
} else {
setUpComments();
}
</script>
<style>
.comments-shell { margin-top: 3rem; padding-top: 1.25rem; border-top: 1px solid #64748b55; }
.comments-shell h2 { font-size: 1.5rem; font-weight: 700; margin-bottom: .5rem; }
.comments-shell p { line-height: 1.6; }
.comments-shell button { margin-top: .75rem; padding: .75rem 1rem; border-radius: .6rem; background: #0e7490; color: white; cursor: pointer; }
.comments-shell button:focus-visible { outline: 3px solid #22d3ee; outline-offset: 3px; }
.comments-shell button:disabled { opacity: .55; cursor: progress; }
.comments-shell :global(.giscus),
.comments-shell :global(.giscus-frame) { width: 100%; }
</style>
This is a reference component, not code that has been deployed on your site. The data-loading="lazy" option delays iframe loading near the viewport; the click gate delays inserting the Giscus script itself.
Why astro:page-load is included
A normal page reload initializes the component once. Astro’s client-side navigation can replace the page without running bundled scripts again. The astro:page-load handler rebinds the button after those navigations. The data-bound guard prevents duplicate click listeners on the same element.
If you don’t use Astro ClientRouter, the component also works through its initial DOM-ready setup.

Figure 2. Giscus is requested only after the reader actively chooses to load comments.
9. Add Giscus to the Shared Article Layout
Locate the Astro layout used for individual blog posts. The file name depends on your project; it might be BlogPostLayout.astro, a page route, or a shared component.
Import your new component:
---
import GiscusComments from '../components/GiscusComments.astro';
---
Then render it once after the article body and before the footer:
<GiscusComments
repo="YOUR_GITHUB_ACCOUNT/blog-discussions"
repoId="YOUR_REAL_REPO_ID"
category="Announcements"
categoryId="YOUR_REAL_CATEGORY_ID"
/>
Use the actual import path and IDs. Never duplicate the comment component in both the article route and the layout; doing so can render two widgets and create confusing behavior.
For a blog managed by Decap CMS, this should be implemented in the shared article layout, not pasted into every Markdown Body field. That way, every published post receives the feature once, without changing existing article content.
If a post has comments disabled, conditionally omit the component using a boolean frontmatter field such as comments: false, but make sure your Content Collection schema and Decap CMS fields agree before introducing it.
10. Configure Light and Dark Themes
Giscus supports several built-in themes. The simplest baseline is:
preferred_color_scheme
This follows the visitor’s operating-system preference. It does not necessarily follow a custom light/dark toggle implemented by your website.
If your site has a theme button that differs from the OS preference, consider switching Giscus theme through its supported parent-to-iframe postMessage configuration API when the theme changes.
Only send configuration messages to the expected Giscus iframe origin (https://giscus.app), not to *. Follow the current advanced usage documentation for the exact message format.
Also check contrast in both modes. A dark iframe against a light page can look disconnected even when technically functional.
11. Configure CSP on Cloudflare Pages
A strict Content Security Policy can block the Giscus script or iframe.
Depending on the existing policy, your site may need to allow:
script-src: https://giscus.app
frame-src: https://giscus.app
These are directions to evaluate, not a complete CSP header to copy over your current policy. Preserve the directives already needed by Astro, Decap CMS, Turnstile, consent management, and other authorized scripts.
Cloudflare Pages can set headers for static responses using public/_headers. Pages Functions responses require separate treatment; _headers does not automatically govern those dynamic responses.
Roll out changes in Report-Only mode first, review console and CSP reports on preview deployments, and enforce only after a successful compatibility check.
Do not weaken a strict policy with broad allowances such as script-src * simply to make a widget work.
12. Respect Privacy and User Expectations
Giscus advertises a no-tracking, no-ads model. Nevertheless, loading the widget contacts a third-party service, and a reader who posts a comment uses GitHub authentication and GitHub’s own terms and privacy practices.
That creates responsibilities for a website operator:
- Explain that comments are hosted by GitHub Discussions.
- Let readers know a GitHub account is required to post.
- Link to your relevant privacy disclosures.
- Decide whether comment loading requires a specific consent choice in your jurisdiction.
- Avoid automatically recording comment authors or text in your own analytics without a clear purpose.
- Offer another channel, such as the contact page, for readers who do not use GitHub.
The opt-in loading button is useful, but it does not replace a legal privacy assessment or your existing website consent mechanism.
13. Moderate Comments and Prevent Abuse
Once enabled, Giscus comments belong to discussions in the selected GitHub repository.
You can review discussions, edit or delete comments under applicable permissions, and lock unproductive conversations. GitHub’s discussion moderation features are useful, but they are not a substitute for an editorial policy.
Set a few clear rules:
- Keep comments relevant to the article.
- Do not post credentials, access tokens, personal data, or private log files.
- Use constructive language when reporting bugs.
- Report spam and malicious links.
- Do not treat a commenter’s unverified code snippet as official documentation.
For technical posts, encourage people to include version numbers and minimal reproduction steps when reporting a problem.
14. Avoid Common Implementation Mistakes
Mistake: Using a private repository. Visitors cannot use Giscus correctly if Discussions are not publicly accessible. Create a separate public discussions repository instead of exposing private source code.
Mistake: Copying someone else’s repo-id or category-id. Generate configuration for your own repository and category at giscus.app.
Mistake: Using a different mapping strategy for each article. Choose a site-wide policy and document how renamed slugs are handled.
Mistake: Treating lazy iframe loading as full script consent. Lazy iframe loading still permits the external script to load. Use a click gate if avoiding initial third-party requests is a requirement.
Mistake: Forgetting CSP. A script may appear in your HTML but fail in the browser because the policy blocks it.
Mistake: Testing only with a logged-in GitHub account. Test as a logged-out reader too; basic reading and commenting are different experiences.
Mistake: Claiming that user comments improve SEO automatically. Search engines evaluate pages in many ways; unmoderated comments can be low-quality or harmful to reader trust.
15. Test the Integration Before Publishing
Start with a preview deployment and verify at least three article URLs, including an older article with a long slug.
| Test | Expected behavior |
|---|---|
| Open an article without clicking | No Giscus request initiated by this component |
| Click Load comments | Script and iframe load successfully |
| Open as a logged-out reader | Existing discussion can be viewed as permitted |
| Try to comment | GitHub authorization is requested |
| Visit a second article | It maps to its own discussion |
| Refresh and revisit | The correct thread is preserved |
| Use an old slug redirect | New URL mapping is reviewed deliberately |
| Switch light/dark mode | Widget remains readable |
| Use a phone screen | iframe stays within viewport width |
| Enable CSP | Script and iframe are not unexpectedly blocked |
| Disable third-party scripts | Article content remains readable |
| Moderate a test comment | GitHub changes are reflected appropriately |
In browser DevTools, open the Network tab and filter for giscus.app. With the click-to-load component, that domain should not be requested by this component before clicking. This claim assumes no other page element independently loads Giscus.
Then use the Performance panel or Lighthouse to compare pages with and without the widget. Do not invent a performance benefit; measure any difference under repeatable test conditions.

Figure 3. Verify repository access, mapping, privacy and user experience before enabling Giscus on every article.
16. Optional: Restrict Which Origins Can Embed Discussions
Giscus offers a giscus.json configuration file in the GitHub repository hosting the discussions. The origins option can restrict which website origins are allowed to embed those discussions.
An illustrative configuration is:
{
"origins": ["https://duonghoangnam.com"],
"originsRegex": ["^http://localhost:[0-9]+$"]
}
The localhost pattern is useful during local development. Review it before production and remove test origins if they are unnecessary.
If you use Cloudflare preview domains, include only the preview origins you intentionally trust. Do not add an unrestricted wildcard without considering its implications.
This configuration does not make a public discussion private. It only controls which origins may embed it through Giscus.
17. Costs, Limitations, and Alternatives
Giscus describes itself as free and open source. It does not require you to maintain a database or deploy a comments API on Cloudflare Pages.
However, it is not free of operational responsibilities: somebody still needs to moderate discussions, maintain the integration, and respond to legitimate feedback.
Consider an alternative if:
- Most readers have no GitHub account.
- You need private comments.
- You require ownership of all user data in your own database.
- You need extensive moderation, paid support, or custom access controls.
- Your privacy policy does not permit this type of external embed.
For general inquiries, a secure contact form may be simpler. For subscribers, a double-opt-in newsletter can be a better way to build a recurring audience. Comments serve a different goal: public, contextual conversation attached to individual articles.
18. Frequently Asked Questions
Is Giscus free to use with Astro?
Giscus is a free, open-source GitHub Discussions-based comment system. Check current GitHub account and repository limits for your own use case.
Do readers need GitHub accounts to comment?
Yes. They must authorize the Giscus app through GitHub to post. Viewing discussions generally does not require the same sign-in flow.
Can I use Giscus with a private Astro repository?
Yes, provided the separate repository that stores Giscus Discussions is public and properly configured. Your website source repository can remain private.
Can Decap CMS manage Giscus comments?
Not directly in this architecture. Decap CMS edits article content in Git; Giscus stores comments in GitHub Discussions.
Does Giscus work on Cloudflare Pages?
Yes. The widget runs in the browser and can be embedded in pages served from Cloudflare Pages. Check CSP and any consent requirements on your deployment.
Will comments automatically improve SEO?
No. Helpful discussion may add value for readers, but there is no guaranteed ranking gain. Keep the page useful even when comments are not loaded.
What happens when I rename an article URL?
Pathname-based mapping may no longer find the original discussion. Handle article URL changes and discussion continuity as a deliberate migration task.
What is the difference between lazy loading and click-to-load?
Lazy loading postpones iframe fetching based on scroll position. Click-to-load postpones insertion of the Giscus script until the reader chooses to load the comments.
19. Final Thoughts
Giscus is a practical way to give a static Astro blog a public conversation space without building a full commenting backend.
The strongest implementation is not simply a script pasted at the bottom of a page. It has a stable URL mapping policy, clear repository permissions, an accessible loading experience, a privacy explanation, CSP compatibility and active moderation.
For a developer-focused blog, GitHub Discussions can work particularly well because readers may already be familiar with GitHub and enjoy sharing implementation details.
Start by enabling comments on a few technical guides. Watch the quality of discussion and feedback before adding the widget to every article.
Continue Reading
- How to Build an Astro Blog with Decap CMS and Cloudflare Pages — Set up the publishing foundation and reusable article layout.
- How to Find and Fix Broken Links in Astro with GitHub Actions — Check URLs, including renamed article slugs, before publishing.
- How to Build a Secure Contact Form in Astro with Cloudflare Turnstile and Pages Functions — Provide another channel for readers who don’t use GitHub.
Official Documentation and Resources
- Giscus — Official configuration
- Giscus — Advanced usage
- GitHub — Discussions
- GitHub — Moderating discussions
- Astro — Client-side scripts
- Astro — View Transitions
- Cloudflare Pages — Custom headers
Technical disclosure: The component and configuration files are reference examples based on official documentation. They have not been deployed or end-to-end tested on DuongHoangNam.com, and no real GitHub repository or Giscus IDs are included.






