Back to blog index

Loading menu items asynchronously

It always bugged me that in order to render any page where the user is logged in I had to do a number of database queries to be able to render the notifications and main menu. Specifically:

  • Unread messages
  • Unread notifications
  • Bra count and reputation on main menu

That required to query 3 potentially big tables on each page slowing down the initial render for all.

I just finally got around making a separate endpoint under where all this information is calculated and a piece of JS on all pages will hit this URL to get the right data. Of course the DB queries are still made, but now they happen after the page has rendered so I don't have to worry about those slowing the render time.

The hack

The funny thing about this separate document is that it could not hold only the inside of the notification menu but many small chunks of HTML to render pieces on separate places, so there is this bunch of HTML dropped, out of which I cherrypick which elements I want to plaster on each part of the page :)

January 10, 2014
comments powered by Disqus