Skip to content

Move scripts on the rustdoc template into head and apply the defer attribute #90872

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

Merged
merged 1 commit into from
Nov 22, 2021
Merged

Move scripts on the rustdoc template into head and apply the defer attribute #90872

merged 1 commit into from
Nov 22, 2021

Conversation

ken-matsui
Copy link
Contributor

Closes #90719

@rust-highfive
Copy link
Contributor

r? @ollie27

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 13, 2021
@jyn514
Copy link
Member

jyn514 commented Nov 18, 2021

r? @jsha

@rust-highfive rust-highfive assigned jsha and unassigned ollie27 Nov 18, 2021
@jyn514 jyn514 added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Nov 18, 2021
Copy link
Contributor

@jsha jsha left a comment

Choose a reason for hiding this comment

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

Generally looks good, thanks for picking this up! One small change to request.

@@ -13,13 +13,23 @@
href="{{static_root_path | safe}}rustdoc{{page.resource_suffix}}.css" {# -#}
id="mainThemeStyle"> {#- -#}
{{- style_files | safe -}}
<script id="default-settings" {# -#}
<script defer id="default-settings" {# -#}
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's omit the defer here. This doesn't actually load any external JS, and is just a convenient place to hang some data- attributes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh and there's even a citation from MDN: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-defer

defer
Warning: This attribute must not be used if the src attribute is absent (i.e. for inline scripts), in this case it would have no effect.

<script src="{{static_root_path | safe}}storage{{page.resource_suffix}}.js"></script> {#- -#}
<script src="{{page.root_path | safe}}crates{{page.resource_suffix}}.js"></script> {#- -#}
<script defer src="{{static_root_path | safe}}storage{{page.resource_suffix}}.js"></script> {#- -#}
<script defer src="{{page.root_path | safe}}crates{{page.resource_suffix}}.js"></script> {#- -#}
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, storage and crates JS should not get the defer attribute. They are both on the critical path for rendering the page, so we actually want them to block page render, rather than cause a re-style later.

As an example of why this is important, try changing to a dark theme, and then reloading the page. If storage has the defer attribute, you'll see the page first load with light styles and then with dark (assuming your system default theme is light).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jsha
Thank you so much for your extremely clear review! I've made changes as you show :)

@jsha jsha added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 20, 2021
@jyn514 jyn514 added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 20, 2021
@jsha
Copy link
Contributor

jsha commented Nov 21, 2021

@bors r+

Thanks @ken-matsui !

@bors
Copy link
Collaborator

bors commented Nov 21, 2021

📌 Commit 88787a3 has been approved by jsha

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 21, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 21, 2021
…plate, r=jsha

Move `scripts` on the rustdoc template into `head` and apply the `defer` attribute

Closes rust-lang#90719
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 21, 2021
…plate, r=jsha

Move `scripts` on the rustdoc template into `head` and apply the `defer` attribute

Closes rust-lang#90719
@bors
Copy link
Collaborator

bors commented Nov 22, 2021

⌛ Testing commit 88787a3 with merge 80f5f60...

@bors
Copy link
Collaborator

bors commented Nov 22, 2021

☀️ Test successful - checks-actions
Approved by: jsha
Pushing 80f5f60 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Nov 22, 2021
@bors bors merged commit 80f5f60 into rust-lang:master Nov 22, 2021
@rustbot rustbot added this to the 1.58.0 milestone Nov 22, 2021
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (80f5f60): comparison url.

Summary: This benchmark run did not return any relevant changes.

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

@ken-matsui ken-matsui deleted the add-defer-to-rustdoc-template branch November 22, 2021 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move main and extra scripts to top of page and use defer
8 participants