We have moved to Github. Please open tickets there.

Opened 2 years ago

Last modified 13 months ago

#2718 reopened Enhancement

Move all js to footer

Reported by: ewinslow Owned by:
Priority: normal Milestone: Needs Review
Component: Core Version: 1.7
Severity: minor Keywords:
Cc: brett@…, hellekin@… Difficulty:

Description (last modified by ewinslow)

It makes a huge difference in page render time (hundreds of milliseconds) to move scripts from the head to the footer of the page. We should really try to do this if at all possible.

At the very least, they definitely need to come after the CSS.

Change History (7)

comment:1 Changed 2 years ago by hellekin

  • Cc hellekin@… added

As most Javascript uses the DOM and will only start when it's fully loaded (JQuery), it makes a lot of sense to defer it to the last moment, i.e., just before </body>. The rendering engine can then start displaying the document before the script is downloaded, as the <script> tags don't use any space. In the real world, counting network latency, it can definitely give the user a better feeling. Some script are especially long to bootstrap (e.g., Google Analytics) and can really slow down the rendering if coming too early.

I recommend YSlow, the Yahoo! extension to Firebug to testdrive page's speed and find ways to optimize it.

comment:2 Changed 2 years ago by cash

As long as our JavaScript files are being registered through elgg_register_js(), this should be trivial as it has a location parameter ('head' or 'footer').

comment:3 Changed 2 years ago by ewinslow

But it means plugins can't be allowed to insert js that relies on jQuery or elgg. That's what I'm most concerned about. Do we just say "don't do that, or you're out of luck"?

comment:4 Changed 2 years ago by cash

By insert - you mean inline inserts, right?

We could leave it in the head by default and add a configuration to move it to the footer. That or you could write a plugin that moves the js to the footer if this is desired.

comment:5 Changed 2 years ago by ewinslow

Yea, inline inserts. The trouble with making it a plugin is that I won't have control over other plugins. If we make this a feature of core, then that will force plugins to adhere to best practices.

comment:6 Changed 2 years ago by cash

  • Resolution set to wontfix
  • Status changed from new to closed

Closing this since a plugin can move all javascript to footer if desired on a site in 1.8 with new elgg_register_js code.

comment:7 Changed 13 months ago by ewinslow

  • Description modified (diff)
  • Resolution wontfix deleted
  • Status changed from closed to reopened

I really think we ought to reconsider this and take a more opinionated stance here. If plugins are inserting javascript into the middle of the page, they're doing it wrong, and I don't think we should have to support that.

At the very least we could make the footer the default location, forcing plugins to move the js *up* if that's what they really need to do.

Note: See TracTickets for help on using tickets.