Skip to content

[codex] Optimize SEO performance and security hardening#193

Merged
ThisIs-Developer merged 2 commits into
mainfrom
codex/seo-performance-security-hardening
Jun 25, 2026
Merged

[codex] Optimize SEO performance and security hardening#193
ThisIs-Developer merged 2 commits into
mainfrom
codex/seo-performance-security-hardening

Conversation

@ThisIs-Developer

Copy link
Copy Markdown
Owner

PR Title

[Phase 1 | Phase 2 | Phase 3]: Improve SEO metadata, load path, CSP hardening, and MathJax lifecycle cleanup

Investigation Summary

  • Current State: Static Markdown Viewer app with existing canonical, hreflang, JSON-LD, deferred CDN libraries, SRI, service worker caching, DOMPurify sanitization, worker rendering, and cleanup for STL/object URL resources.
  • Issues Identified:
    • No Content Security Policy was present.
    • One inline onload handler blocked strong CSP adoption.
    • Default Markdown was stored in a non-executed <script type="text/markdown">.
    • Bottom bootstrap.bundle and script.js were not deferred.
    • JSON-LD lacked feature/version detail.
    • PWA manifest lacked stable id, scope, and categories.
    • MathJax could typeset before ready and could race against preview DOM replacement.
  • Optimization Opportunities: Tighten metadata, remove inline handler/script-like content, defer scripts, add CSP, and serialize/clear MathJax rendering state.

Changes Made

Phase 1: SEO Optimization

  • Updated title/Open Graph/Twitter title to target secure online Markdown editor/previewer search intent.
  • Added max-image-preview:large, application-name, theme-color, og:site_name, JSON-LD softwareVersion, and a 5-item featureList.
  • Added manifest id, scope, and categories.
    Verification: Static comparison: JSON-LD feature count 0 -> 5; manifest identity/scope/categories absent -> present.

Phase 2: Website Performance

  • Deferred bottom Bootstrap/app scripts.
  • Removed the Bootstrap Icons inline preload onload, replacing it with a normal stylesheet link so CSP can block inline script execution.
  • Converted default Markdown storage from <script type="text/markdown"> to hidden <textarea>.
    Verification: Static comparison: deferred scripts 6 -> 8, inline onload handlers 1 -> 0, text-markdown script tags 1 -> 0; local post-change app-ready sample averaged 1082 ms across 5 reloads.

Phase 3: Memory Management & Security

  • Added a CSP meta policy restricting script/connect/style/font/img/media/worker sources while preserving current CDN, GitHub import, diagram, and map workflows.
  • Added a SHA-256 hash for the inline JSON-LD block instead of allowing arbitrary inline scripts.
  • Added MathJax readiness serialization, connected-node filtering, preview cleanup via typesetClear, and removed the redundant AMS loader request.
    Verification: Fresh browser interaction inserted math Markdown, rendered 2 MathJax containers, preview state stayed ready, and fresh warning/error logs were empty.

Verification Results

  • No existing functionality broken: editor and preview rendered Markdown/math successfully.
  • Performance path improved: deferred scripts 6 -> 8, inline handler count 1 -> 0.
  • Security hardening added: CSP present, no arbitrary inline script allowance; no CVE-specific dependency change.
  • SEO improvements confirmed: title/robots/JSON-LD/manifest metadata updated.
  • Code review completed: diff limited to index.html, manifest.json, script.js.

Additional checks:

  • node --check script.js
  • node --check preview-worker.js
  • manifest.json parsed successfully
  • Browser verification on http://127.0.0.1:8080

Conclusion

The app already had good sanitizer/SRI/caching foundations, but improvements were necessary. This PR adds measurable SEO/security/performance hardening while keeping the changes targeted and reversible.

@vercel

vercel Bot commented Jun 25, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
markdown-viwer Ready Ready Preview, Comment Jun 25, 2026 11:59am

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 25, 2026

Copy link
Copy Markdown

Deploying markdown-viewer with  Cloudflare Pages  Cloudflare Pages

Latest commit: fd3b18d
Status: ✅  Deploy successful!
Preview URL: https://044efe81.markdown-viewer.pages.dev
Branch Preview URL: https://codex-seo-performance-securi.markdown-viewer.pages.dev

View logs

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying markdownviewer with  Cloudflare Pages  Cloudflare Pages

Latest commit: fd3b18d
Status: ✅  Deploy successful!
Preview URL: https://dec3449c.markdownviewer.pages.dev
Branch Preview URL: https://codex-seo-performance-securi.markdownviewer.pages.dev

View logs

@ThisIs-Developer

Copy link
Copy Markdown
Owner Author

Update: Inline LaTeX duplicate render fix

Added a follow-up fix for the initial paste lifecycle bug reported with:

## 1. Basic Arithmetic & Algebra

Inline: The quadratic formula is $x = \dfrac{-b \pm \sqrt{b^2 - 4ac}}{2a}$ and it has two roots.

Root Cause

The preview math pipeline could re-process already-rendered MathJax output during the initial paste path. This happened because broad preview-root MathJax targets were reused during forced/no-op post-processing, and MathJax startup/loading was not centralized enough to avoid overlapping lifecycle work.

Fix

  • Reuse in-flight lazy script/style loads instead of creating duplicate loader promises.
  • Centralize MathJax configuration/loading through ensureMathJaxReady().
  • Disable MathJax startup auto-typesetting so only the app-controlled preview path typesets.
  • Invalidate pending MathJax work when preview DOM is replaced.
  • Target only text blocks that still contain raw TeX delimiters (p, li, .math-block, etc.) instead of handing the whole preview root back to MathJax.

Verification

  • Reproduced the bug before the final fix: initial paste produced paragraphMjxCount: 2 and duplicated formula text.
  • Verified after the fix on a fresh local origin:
    • Immediately after paste: paragraphMjxCount: 1, previewMjxCount: 1
    • After reload: paragraphMjxCount: 1, previewMjxCount: 1
    • Fresh warning/error logs: empty
  • Checks passed:
    • node --check script.js
    • node --check preview-worker.js
    • manifest.json parse check

@ThisIs-Developer ThisIs-Developer marked this pull request as ready for review June 25, 2026 12:01
@ThisIs-Developer ThisIs-Developer merged commit b73e637 into main Jun 25, 2026
6 checks passed
@ThisIs-Developer ThisIs-Developer deleted the codex/seo-performance-security-hardening branch June 25, 2026 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant