Skip to content

Inline intent doc when fetching an intent index.html#4853

Open
zatteo wants to merge 3 commits into
masterfrom
feat/inline-intent
Open

Inline intent doc when fetching an intent index.html#4853
zatteo wants to merge 3 commits into
masterfrom
feat/inline-intent

Conversation

@zatteo

@zatteo zatteo commented Jul 16, 2026

Copy link
Copy Markdown
Member

Eliminate the GET /intents/:id fetch request that the intent service app (inside the iframe) makes to the stack, by inlining the full intent object into the HTML response when the stack serves the service app's index.html.

The stack already loads the intent from CouchDB in handleIntent() when serving a page with ?intent=<id> but currently discards it after setting CSP frame-ancestors rules. This change keeps the loaded intent and serializes
it into a <script> tag in the <head>, so the service app can read it synchronously from window.__COZY_INTENT__ instead of making a second network round-trip.

Estimated save: 1 blocking API call, 233ms (average of 5 call on stg.lin-saas.com)

Front end: github.com/linagora/cozy-libs/pull/3082

@zatteo
zatteo force-pushed the feat/inline-intent branch from e3283ea to 82aa654 Compare July 16, 2026 13:01
@zatteo
zatteo requested review from shepilov and taratatach and removed request for shepilov July 16, 2026 13:02
Comment thread web/apps/serve.go
))

intentTemplate = template.Must(template.New("intent-data").Parse(
`<script>window.__COZY_INTENT__ = JSON.parse({{.}})</script>`,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested it locally? It's supposed to be blocked by CSP

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh interesting. I tested locally but by default I use --disable-csp. So in this case I can add it in a meta tag that will be fetched in the DOM and parsed like existing CozyData.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<script type="application/json"> shoudl help

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.

2 participants