[2.x] bbcode: highlight.js loader runs once per code block and adds ~1.1 s TBT on mobile
Maintainers usually reply within 1 day
@imorland is already working on this.
Since Nov 16, 2026.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- javascript, php
- Domain
- frontend, performance
Research direction
Start with extensions/bbcode/src/Configure.php and its adaptHighlightJs() entry point, then inspect the s9e CODE template behavior described in the issue. Compare the loader’s repeated script requests and Lighthouse measurements against the suggested approaches; the issue does not choose a solution, so agree on the design with maintainers before implementation. Done means an agreed approach addresses the performance cost and the opt-out or configuration needs.
Written by the indexing model from the issue text.
Description
On any discussion with code blocks, the bbcode extension's CODE template makes the browser load s9e/hljs-loader from cdn.jsdelivr.net, and running that loader is a large share of the page's main-thread blocking time.
How it gets there: extensions/bbcode/src/Configure.php adds the CODE BBCode from the s9e repository and adaptHighlightJs() appends a small inline script to the template. The s9e template itself emits <script async data-hljs-style="github" src="https://cdn.jsdelivr.net/gh/s9e/[email protected]/loader.min.js"> inside each <pre>. The rendered HTML therefore contains one loader <script> per code block (10 on the page below), and the loader then fetches highlight.min.js 11.11.0 and a github.min.css from the same CDN.
Measurement: Lighthouse 13.5.0, mobile emulation, 4x CPU slowdown, https://linkrobins.com/d/61-support (Flarum 2.0.2, 10 code blocks), run twice:
- Total Blocking Time 2,790 ms and 2,670 ms.
- Lighthouse "bootup time":
[email protected]/loader.min.jsis the second largest script after forum.js, about 1,159 ms total, 1,117 ms of it scripting.highlight.min.jsadds another ~81 ms. - Performance score 0.36 and 0.38. The page has no other third-party script of significance.
I have not profiled inside the loader, so I can't say how much of the cost is the per-block repeated script elements versus the loader itself.
Suggestions, in no particular order:
- Emit the loader once per post (or once per page) instead of once per code block.
- Load it after load or on idle (
requestIdleCallback), and only highlight blocks when they are near the viewport. - Offer a smaller build with common languages instead of whatever the loader pulls in.
- Provide a config/setting or extender hook to disable syntax highlighting or point it at a self-hosted copy, so forums that care about TBT, CSP or third-party requests can opt out.
I'm not proposing a code change, as this looks like a design decision for the maintainers. Related earlier discussion in s9e/TextFormatter: #193 (customize the hljs load URL) and #206.
- Dominant language
- PHP
- Stars
- 6.8k
- Forks
- 891
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 209
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from flarum/framework
-
type/accessibility type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
Default language is ignored for anyone who chose a language, when the language selector is hiddenPossibly taken @1AbdullahButt claimed this 15 days ago. Opentype/bug
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
Maintainers usually reply within 1 day
-
[2.x] False CLI/Web PHP mismatch when /usr/bin/php differs from the site's FPMPossibly taken @lazerg claimed this 15 days ago. Opentype/bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
[2.x] A filter on a resource without a searcher returns a 500Possibly taken @imorland claimed this today. Opentype/bug
flarum/framework#5578 · 1 assignee ·
Maintainers usually reply within 1 day
All issues in flarum/framework
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 87/100
Sylius/Sylius#19359 · 1 comment ·
Maintainers usually reply within 1 day
-
Add php 8.6Open
Difficulty 1/5 Under an hour Newbie friendliness 66/100
mailersend/mailersend-php#199 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Configuration new tool
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
novalo-dev/Prestashop-MCP-Server#366 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 10 days