Closed NewFuture closed 6 years ago
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 😄
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?
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.
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/
.
It will display a screen like this screenshot, before jumping to new URL.
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.
@jekyllbot: merge +minor
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 :)