Skip to content

Conversation

NewFuture
Copy link
Contributor

Just changed the order of the scripts.
In most browsers (such as chrome), it will execute the javascript before page rendering.
So that the page will redirect without the splash white screen :)

Just changed the order of the scripts.
In most browsers (such as chrome), it will execute the javascript before page rendering.
So that the page will redirect without the splash white screen :)
Copy link
Member

@pathawks pathawks left a comment

Choose a reason for hiding this comment

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

Would it work just as well if we put it right above <h1>?

@NewFuture
Copy link
Contributor Author

NewFuture commented Jul 4, 2017

Of course.
But it will parse the refresh meta firstly, which is unnecessary when the JavaScript is enabled.
We just want to it redirect as soon as possible 😄

@pathawks
Copy link
Member

It seems the <meta> should be parsed first, and the JavaScript only serve as a backup incase something weird happens. Is that not what is happening?

@NewFuture
Copy link
Contributor Author

Not exactly.
The script should be paresed at first and the <meta> is a back.

Most of the browsers will parse and execute the inline JavaScript as document order.
This JavaScript code will be executed immediately when parsed. Then it the browser will redirect and stop to parse and render the HTML document.

For an example

Try this code in Chrome

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script>
        alert(1);
        location="https://github.com/";
    </script>
    <title>Title</title>
    <meta http-equiv="refresh" content="0; url=http://jekyllrb.com/">
    <script>
        alert(2);
    </script>
</html>

It will alert and redirect to https://github.com/ immediately; and it will not show the Title or execute the second JavaScript bock (alert(2)) or redirect ro http://jekyllrb.com/.

For current version

It will display a screen like this screenshot, before jumping to new URL.
image

For this PR

It will not show this screen unless the JavaScript is disabled (the <meta> is a backup).
If the network is slow it will just show the Redirecting… in browser title (without painting the window).
I think this this way it better for both user experience and performance.

@DirtyF DirtyF requested a review from a team April 3, 2018 21:00
@DirtyF DirtyF mentioned this pull request Apr 4, 2018
@DirtyF
Copy link
Member

DirtyF commented Jun 29, 2018

@jekyllbot: merge +minor

@jekyllbot jekyllbot merged commit 97c2841 into jekyll:master Jun 29, 2018
jekyllbot added a commit that referenced this pull request Jun 29, 2018
@jekyll jekyll locked and limited conversation to collaborators Jun 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants