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

Redirect from prerendered pages with <script> #9907

Closed
Rich-Harris opened this issue May 11, 2023 · 2 comments · Fixed by #9911
Closed

Redirect from prerendered pages with <script> #9907

Rich-Harris opened this issue May 11, 2023 · 2 comments · Fixed by #9911
Assignees

Comments

@Rich-Harris
Copy link
Member

Describe the problem

When prerendering, if we encounter a redirect it gets baked out as an HTML file with a <meta> refresh tag:

writeFileSync(
dest,
`<meta http-equiv="refresh" content=${escape_html_attr(`0;url=${location}`)}>`
);

Turns out (h/t @cramforce) it's actually quicker to use a <script>:

<script>onload=() => location.href = "${url}"</script>

(Do we even need the onload? Would it be quicker still without it?)

Describe the proposed solution

Do both — <script> for speed, <meta> for reliability.

Alternatives considered

No response

Importance

nice to have

Additional Information

No response

@cramforce
Copy link

The onload is for if you want to guarantee the page gets painted (like for a loading dialog UI or similar). It would only be good if the page has zero sub-resources, otherwise it would lead to unpredictable delays.

@Conduitry
Copy link
Member

In this case, we're using a prerendered page to simulate a server side redirect, and the file will contain only the <meta> tag - there are no user-visible elements at all that we have to worry about getting partially displayed. It sounds like we should just add a direct <script>location.href = "..."</script> then.

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 a pull request may close this issue.

4 participants