alphagov / tech-docs-gem

Gem to distribute the tech docs project
https://tdt-documentation.london.cloudapps.digital/
MIT License
15 stars 38 forks source link

Simplify how JavaScript is initialised and slightly improve performance #95

Closed aliuk2012 closed 4 years ago

aliuk2012 commented 5 years ago

This is part of a bigger piece of work to remove the dependency on jQuery.

There is no need to rely on jQuery's document.ready() method. By placing application.js at the bottom of the page, the script will be executed after all preceding DOM is loaded anyway.

There is also a slight performance improvement (HTML parsing and loading of CSS and images isn't blocked by the scripts)

jonheslop commented 5 years ago

Nice! I have been using

  document.addEventListener('DOMContentLoaded', function() {
    // stuff
  });

as a vanilla alternative but if you’re sure everything loads in the right order then 👌

NickColley commented 4 years ago

I've bumped this ready to merge, I think some newer changes (probably move to the Design System) moved the script location anyway so this feels good to merge.

NickColley commented 4 years ago

Hmm this approach no longer seems to work anymore, going to close for now, will be revisited when/if we remove jQuery. Thanks for the help anyway.