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

feat(sendRedirect): add refresh meta fallback for static generated responses #153

Merged
merged 5 commits into from
Jul 26, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/utils/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export function defaultContentType (event: CompatibilityEvent, type?: string) {
export function sendRedirect (event: CompatibilityEvent, location: string, code = 302) {
event.res.statusCode = code
event.res.setHeader('Location', location)
return send(event, 'Redirecting to ' + location, MIMES.html)
// minimal html document that redirects on client side
const html = `<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0; url=${encodeURI(location)}"></head><body></body></html>`
Copy link
Member

Choose a reason for hiding this comment

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

Can you please also add a visual <a> link?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've added it within a <noscript> as otherwise I think it is a better experience not to have text flash on the screen and then off again. Let me know if you feel differently.

Copy link
Member

Choose a reason for hiding this comment

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

I see but with browser fallback, there is anyway a flash to white...

Copy link
Member Author

@danielroe danielroe Jul 26, 2022

Choose a reason for hiding this comment

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

I thought most 'new tabs'/hard-reloads defaulted to white when loading. So there would be no flash when it loads unless we have text on it.

return send(event, html, MIMES.html)
}

export function appendHeader (event: CompatibilityEvent, name: string, value: string): void {
Expand Down