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

Remove html_head_javascript() and relocate js to bottom of the page to speed up page rendering #605

Closed
wants to merge 4 commits into from
Closed

Conversation

syncguru
Copy link
Contributor

@syncguru syncguru commented May 4, 2015

Fixes #13285: Move script inclusions from HEAD to document footer

foreach ( $g_scripts_included as $t_script_path ) {
html_javascript_link( $t_script_path );
}

event_signal( 'EVENT_LAYOUT_BODY_END' );
Copy link
Member

Choose a reason for hiding this comment

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

Should the body end event proceed the javascript, so the javascript is right before the closing body tag?

@vboctor
Copy link
Member

vboctor commented May 15, 2015

The title of the commit is too long. The issue title is more compact and I think conveys the message. We try to have commit titles be 50 characters or less.

Otherwise 👍 with some minor comments.

@dregad
Copy link
Member

dregad commented May 16, 2015

Are we sure that this really has no side effects ? Are all of the cases indeed covered by $document.ready() ? I'm concerned about the jscalendar (we really need to replace this thing at some point in the near future !), and also what about plugins ? They could be using require_js() too (didn't check)

@vboctor
Copy link
Member

vboctor commented May 16, 2015

From Best Practices for Speeding Up Your Web Site

Put Scripts at the Bottom
The problem caused by scripts is that they block parallel downloads. The HTTP/1.1 specification suggests that browsers download no more than two components in parallel per hostname. If you serve your images from multiple hostnames, you can get more than two downloads to occur in parallel. While a script is downloading, however, the browser won't start any other downloads, even on different hostnames.

In some situations it's not easy to move scripts to the bottom. If, for example, the script uses document.write to insert part of the page's content, it can't be moved lower in the page. There might also be scoping issues. In many cases, there are ways to workaround these situations.

An alternative suggestion that often comes up is to use deferred scripts. The DEFER attribute indicates that the script does not contain document.write, and is a clue to browsers that they can continue rendering. Unfortunately, Firefox doesn't support the DEFER attribute. In Internet Explorer, the script may be deferred, but not as much as desired. If a script can be deferred, it can also be moved to the bottom of the page. That will make your web pages load faster.

@dregad
Copy link
Member

dregad commented May 17, 2015

For the record: I'm not saying this shouldn't be done, I just want to make sure we're not introducing any regressions.

@vboctor
Copy link
Member

vboctor commented May 17, 2015

I don't have a position either, just posted the reference. I suggest we come up with the list of features that we want to make sure work properly:

  • jscalender for reports / due date picker
  • filtering javascript (clicking field, switching filters, ...)
  • custom field default value (string vs. text area switching).
  • changing current project.

@dregad anything else you suggest checking?

@syncguru
Copy link
Contributor Author

@dregad the issues that result from moving JS files or changing their loading order usually too severe to go unnoticed, that said, a quick testing will reveal problems quite easily. As such I don't consider this change to be risky.

@dregad
Copy link
Member

dregad commented May 22, 2015

Not sure what you did with the pull request here, but I suggest you rebase the branch on top of latest master and push it again.

@syncguru
Copy link
Contributor Author

Not sure what went down either. Rebased the branch... should be good now.

@vboctor
Copy link
Member

vboctor commented Aug 17, 2015

Any reason why this change is not merged yet?

@dregad
Copy link
Member

dregad commented Aug 17, 2015

No objections from me, as long as the

quick testing will reveal problems quite easily

has actually been performed...

@syncguru
Copy link
Contributor Author

Yes, this was tested. I need to update this PR to resolve conflicts though.

@syncguru
Copy link
Contributor Author

@vboctor @dregad - this PR is updated and tested.

@vboctor
Copy link
Member

vboctor commented Aug 20, 2015

👍

dregad added a commit that referenced this pull request Aug 20, 2015
This is Rafik's original branch rebased on master.
Pull request #605
@dregad
Copy link
Member

dregad commented Aug 20, 2015

Merged. Thanks Rafik !

@dregad dregad closed this Aug 20, 2015
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 this pull request may close these issues.

3 participants