Repository navigation
Caline 缺陷修复·前端:缓存头 + bundle 自动初始化(QA #7 缺陷③④) - #18
Merged
todosdev[bot] merged 3 commits intoNov 18, 2026
Merged
Conversation
Add web/public/_headers to provide 24h cache-control and CORS headers for /client/* assets. Implement autoInit and scheduleAutoInit in client bundle to support zero-config one-line script embedding with data-* attributes, window.CALINE_CONFIG fallback, and container auto-creation. Checkpoint: HyyoBCjDuicFPajSTdAcA
Gate autoInit to execute only when explicit intent is declared via window.CALINE_CONFIG, script data-* attributes, or caline containers. Prevent inserting container div when script is located inside head. Checkpoint: s66D420pXvmab99oeQc3R
…e-77b7-942e-9596759a5465
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.
Summary
web/public/_headers中增加 Cloudflare Static Assets 自定义头规则,为/client/*配置 24h 强缓存与 CORS 头(public, max-age=86400, stale-while-revalidate=604800,Access-Control-Allow-Origin: *),兼顾边缘长缓存与版本平滑更新。autoInit()与scheduleAutoInit(),支持<script>的data-*属性、window.CALINE_CONFIG、或显式#caline容器自动挂载,并杜绝无配置引入时的双实例挂载和在<head>中生成非法 DOM。Caline.init(options)API 100% 兼容;缺省serverURL时优雅降级为location.origin并输出警告,杜绝原有的TypeError崩溃。Changes
web/public/_headers:新建静态资源头配置文件,声明/client/*长缓存(24h max-age + 7d SWR)与开放 CORS,同时为/assets/*提供 1 年 immutable 缓存,构建后自动输出到web/dist/_headers。client/src/index.ts:autoInit()与scheduleAutoInit(),增加严格门控(仅在检测到window.CALINE_CONFIG、<script data-*>或页面显式[data-caline]/#caline时启动)。#caline容器,但严格排除<head>内部 script 避免非法 DOM 结构。CalineWidget构造函数中支持缺省serverURL回退至location.origin,容器打上data-caline-initialized防重复标记,并联动触发[data-caline-count]和[data-caline-pageview]自动填充。client/test/widget.test.ts&client/test/bundle.test.ts:补充 10 项单元测试,覆盖自动初始化、一行 script 嵌入、门控与<head>保护、防重复挂载及_headers配置断言。web/public/client/v1.js:重新打包并同步更新 bundle 产物,构建后 gzip 体积为 8.78KB(严格满足 ≤ 30KB 约束)。Testing
pnpm test:全套 411 个测试全绿(shared 12、client 27、worker 230、web 142)。pnpm lint&pnpm format:check:Biome 检查通过,0 错误 0 警告。pnpm typecheck:client+web+worker三包严格 TypeScript 校验通过。pnpm check:identity:项目身份标识扫描通过,白名单外零残留。pnpm check:deploy:wrangler deploy --dry-run静态资产打包 13 个文件校验通过。