Disable CDN caching for HTML, add Quicklink prefetching
All checks were successful
ci/woodpecker/push/build Pipeline was successful
All checks were successful
ci/woodpecker/push/build Pipeline was successful
- Change Cache-Control from s-maxage=31536000 to max-age=0,must-revalidate for all HTML pages and sitemap (fixes stale content after settings change) - Remove Cloudflare PurgeURLs call since we're not caching HTML at CDN - Add Quicklink for client-side prefetching on public blog pages - Make main branch deploy automatic (remove manual trigger) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
5329167c8c
commit
c662e41b97
4 changed files with 9 additions and 18 deletions
|
|
@ -36,7 +36,6 @@ steps:
|
||||||
image: alpine
|
image: alpine
|
||||||
when:
|
when:
|
||||||
branch: main
|
branch: main
|
||||||
event: manual
|
|
||||||
commands:
|
commands:
|
||||||
- apk add --no-cache openssh-client
|
- apk add --no-cache openssh-client
|
||||||
- mkdir -p ~/.ssh
|
- mkdir -p ~/.ssh
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,8 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="/static/js/main.js"></script>
|
<script src="/static/js/main.js"></script>
|
||||||
|
<script src="https://unpkg.com/quicklink@2.3.0/dist/quicklink.umd.js"></script>
|
||||||
|
<script>quicklink.listen({ignores: [/\/studio/, /\/api\//]});</script>
|
||||||
{{block "scripts" .}}{{end}}
|
{{block "scripts" .}}{{end}}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,7 @@ func (s *Server) blogHome(w http.ResponseWriter, r *http.Request) {
|
||||||
s.recordPageView(q, r, "/", "")
|
s.recordPageView(q, r, "/", "")
|
||||||
|
|
||||||
if html, etag, err := q.GetPage(r.Context(), "/"); err == nil && html != nil {
|
if html, etag, err := q.GetPage(r.Context(), "/"); err == nil && html != nil {
|
||||||
s.servePreRendered(w, r, html, etag, "public, s-maxage=31536000, max-age=0")
|
s.servePreRendered(w, r, html, etag, "public, max-age=0, must-revalidate")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -156,7 +156,7 @@ func (s *Server) blogHome(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
s.servePreRendered(w, r, html, computeETag(html), "public, s-maxage=31536000, max-age=0")
|
s.servePreRendered(w, r, html, computeETag(html), "public, max-age=0, must-revalidate")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) blogList(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) blogList(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
@ -172,7 +172,7 @@ func (s *Server) blogList(w http.ResponseWriter, r *http.Request) {
|
||||||
s.recordPageView(q, r, "/posts", "")
|
s.recordPageView(q, r, "/posts", "")
|
||||||
|
|
||||||
if html, etag, err := q.GetPage(r.Context(), "/posts"); err == nil && html != nil {
|
if html, etag, err := q.GetPage(r.Context(), "/posts"); err == nil && html != nil {
|
||||||
s.servePreRendered(w, r, html, etag, "public, s-maxage=31536000, max-age=0")
|
s.servePreRendered(w, r, html, etag, "public, max-age=0, must-revalidate")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -223,7 +223,7 @@ func (s *Server) blogList(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
s.servePreRendered(w, r, html, computeETag(html), "public, s-maxage=31536000, max-age=0")
|
s.servePreRendered(w, r, html, computeETag(html), "public, max-age=0, must-revalidate")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) blogPost(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) blogPost(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
@ -249,7 +249,7 @@ func (s *Server) blogPost(w http.ResponseWriter, r *http.Request) {
|
||||||
s.recordPageView(q, r, path, slug)
|
s.recordPageView(q, r, path, slug)
|
||||||
|
|
||||||
if html, etag, err := q.GetPage(r.Context(), path); err == nil && html != nil {
|
if html, etag, err := q.GetPage(r.Context(), path); err == nil && html != nil {
|
||||||
s.servePreRendered(w, r, html, etag, "public, s-maxage=31536000, max-age=0")
|
s.servePreRendered(w, r, html, etag, "public, max-age=0, must-revalidate")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -457,7 +457,7 @@ func (s *Server) blogPost(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
s.servePreRendered(w, r, html, computeETag(html), "public, s-maxage=31536000, max-age=0")
|
s.servePreRendered(w, r, html, computeETag(html), "public, max-age=0, must-revalidate")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) canPreview(r *http.Request, tenantID string) bool {
|
func (s *Server) canPreview(r *http.Request, tenantID string) bool {
|
||||||
|
|
@ -543,7 +543,7 @@ func (s *Server) sitemap(w http.ResponseWriter, r *http.Request) {
|
||||||
baseURL := getBaseURL(r.Host)
|
baseURL := getBaseURL(r.Host)
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/xml; charset=utf-8")
|
w.Header().Set("Content-Type", "application/xml; charset=utf-8")
|
||||||
w.Header().Set("Cache-Control", "public, s-maxage=31536000, max-age=0")
|
w.Header().Set("Cache-Control", "public, max-age=0, must-revalidate")
|
||||||
|
|
||||||
w.Write([]byte(`<?xml version="1.0" encoding="UTF-8"?>
|
w.Write([]byte(`<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||||
|
|
|
||||||
|
|
@ -162,15 +162,5 @@ func (s *Server) rebuildSite(ctx context.Context, tenantID string, db *sql.DB, h
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.cloudflare.IsConfigured() {
|
|
||||||
urls := make([]string, len(pages))
|
|
||||||
for i, p := range pages {
|
|
||||||
urls[i] = baseURL + p.path
|
|
||||||
}
|
|
||||||
if err := s.cloudflare.PurgeURLs(ctx, urls); err != nil {
|
|
||||||
slog.Error("rebuildSite: purge cache", "error", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
slog.Info("rebuildSite: complete", "tenantID", tenantID, "pages", len(pages))
|
slog.Info("rebuildSite: complete", "tenantID", tenantID, "pages", len(pages))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue