google / sxg-rs

A set of tools for generating signed exchanges at serve time.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Enable authors to specify SXG-only tags

twifkak opened this issue · comments

For instance if the HTML contains:

<template data-sxg-only>
  <script>log("visit-from-sxg=true")</script>
</template>

then when generating an SXG, rewrite it to:

<script>log("visit-from-sxg=true")</script>

Other possible spellings include <template class=sxg-only> or <script type=text/sxg-only> or <!--[if SXG]>, but the above seems the most general and least likely to collide with existing pages. (But that should be confirmed before implementing.)

Motivation

Enable web publishers to distinguish SXG visits from unsigned visits in their analytics. This could help them track overall usage, or compare performance metrics between the two cohorts. Examples of feature requests for a similar tool (CF ASX):

and/or we could have a simpler API for the common use case. Something like:

<meta name=declare-sxg-var>

becomes something like:

<script>window.isSXG = true</script>

On further thought, we should definitely at least do the first one (probably both). And it should delete the template tag on non-SXG.

This covers another use case: being able to include JS & templates (they can be nested) for lazy-loading personalized elements, without affecting the byte size of the non-SXG version (which can personalize via dynamic HTML instead).

Remaining task is to implement on fastly_compute.

Implementing for fastly_compute should be easy now that process_html.rs exists.