Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sec-fetch-mode check #52

Merged
merged 1 commit into from
Mar 13, 2023
Merged

Add sec-fetch-mode check #52

merged 1 commit into from
Mar 13, 2023

Conversation

thomaswilburn
Copy link
Contributor

I work on some small tools and sites (such as https://github.com/Chalkbeat/powertoys/tree/main/tarot) where it's useful to have live reload built into a static server. However, I often retrieve HTML fragments over fetch (either to add dynamic content, or when writing custom elements that have non-trivial shadow root templates), and the current eleventy-dev-server appends the live reload script tag to these because it doesn't distinguish between page navigation and PJAX-like requests. This change adds a check for the Sec-Fetch-Mode header, and if it is present, only augments the HTML content if the header contains the "navigate" value, meaning that it's being loaded by the browser page navigation and not by client-side code.

This skips adding the live reload script to pages that are retrieved over fetch in browsers that support the Sec-Fetch-Mode header, which is useful for PJAX, custom elements that load their shadow templates asynchronously, or other static client-side apps.
@zachleat zachleat merged commit 9919cec into 11ty:main Mar 13, 2023
@zachleat zachleat added the enhancement New feature or request label Mar 13, 2023
@zachleat zachleat added this to the Eleventy Dev Server v1.0.4 milestone Mar 13, 2023
@zachleat
Copy link
Member

Thank you! Shipping with v1.0.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants