Add static caching via backstage/laravel-static - #39
Open
markvaneijk wants to merge 2 commits into
Open
Conversation
- Replace spatie/laravel-sitemap with a small Blade template: the site only hand-builds a 5-URL sitemap, and laravel-sitemap's spatie/crawler ^9 requirement conflicted with laravel-static's ^8 - Apply StaticResponse middleware to the HTML routes (home, uses, now, aliases, posts index, post pages); sitemap, feed and socials stay dynamic - Config: routes driver, query strings ignored (pages don't vary by query string, and it prevents cache-stuffing via ?ref= URLs), minified HTML - Clear cached pages when a Post is saved or deleted through the model; markdown files added directly to content/posts need a rebuild on deploy - STATIC_ENABLED=true by default, disabled in local .env Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
laravel-sitemap 8.0.0 is the newest version still on spatie/crawler ^8, so it can coexist with backstage/laravel-static; 8.0.1+ require crawler ^9. Pinned exactly until laravel-static supports crawler v9. Cache invalidation on Post events removed — posts are markdown files in content/posts, so model events never fire for real publishes anyway; clear/warm the static cache on deploy instead. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements full-page static caching with backstage/laravel-static, addressing the SEO audit's P1 performance finding: every HTML response currently bypasses the CDN (
cf-cache-status: DYNAMIC) because Laravel renders each request.What changed
spatie/laravel-sitemapto8.0.0— the newest version still onspatie/crawler ^8, so it coexists with laravel-static (8.0.1+ require crawler ^9, which conflicts). Unpin once laravel-static supports crawler v9.StaticResponsemiddleware on all HTML routes:/,/uses,/now,/aliases,/posts, and post pages. Sitemap, feed and socials routes stay dynamic (XML content types and OAuth flows must not be cached as .html).config/static.php):routesdriver,include_query_string: false(pages don't vary by query string; also prevents cache-stuffing via?ref=URLs like the ones in the backlink profile),minify_html: true.content/posts, so model events never fire for real publishes. Clear + warm the cache as a deploy step instead (below).STATIC_ENABLED=trueby default (production picks it up with no env change); local.envsetsfalseso dev stays fresh.Verified locally
storage/app/public/{host}/GET/{path}?.htmlon real requestsSTATIC_ENABLED=falsenothing is written; test suite passesDeploy notes
?in filenames — the package's naming convention):add_header) since the PHP middleware won't run.Upstream findings (backstagephp/laravel-static)
Bugs worth fixing in the package itself:
config('static.files.include_domain')is ignored on writes —createStaticFile()hardcodes$request->getHost()into the path (basePath()honors the flag but is never used there).php artisan static:buildcreates synthetic requests viaRequest::create($route->uri()), so all files land underlocalhost/regardless ofAPP_URL— combined with the above, build output can never be served for a real domain. On-demand caching is unaffected (hence the curl warm-up above).on_termination: true,static:buildwrites nothing at all — the build dispatches via the router, so middlewareterminate()never fires.laravel-static-configpublish tag doesn't exist (publishing works via the provider), and the namespace isBackstage\Static\Laravel, notBackstage\LaravelStatic.spatie/crawler ^9so consumers can use laravel-sitemap ≥ 8.0.1 (v9 is a full API rewrite:Crawler::create(url), renamed fluent methods, new observer signatures).🤖 Generated with Claude Code