Details
-
Type: Bug
-
Status: Done/Fixed
-
Priority: Minor
-
Resolution: Fixed/Completed
-
Affects Version/s: 4.3.0
-
Fix Version/s: 4.5
-
Component/s: None
-
Labels:None
Description
The CiviCRM menu adds a LOT of markup to the page. Looking at the source of a typical drupal+civi page, the civi menu markup weighs in at 33k. The whole html document (drupal + civi content) is only 76k, so that's over 40% of the markup just for the menu.
I propose moving this into a dynamically generated js file. It can be returned from the server like a typical ajax callback, but the browser would treat it like a static file and therefore cache it.
This will significantly speed up civi page load times and reduce load on the server and network. It will magnify the effect of whatever sql optimizations we're doing for the menu tables.
This is the simplest way I can think of to do it:
- Add a server-side callback that returns javascript to render the menu appropriate for the current user. We can re-use our current templates, just need to re-format the output a bit.
- To keep it simple, don't bother with any extra caching of this output, the browser will do that for us.
- On the client-side, replace 33k of menu markup and js with one line: <script src="/path/to/our/callback?cid=123&cachekey=[hash]" />
- Whenever we rebuild the menu or change user permissions, update the value of ?cachekey and it will trigger the client to refetch the js from the server
Note: adding cid as a url arg is not something the server-side callback will pay any attention to (it will get that from the session), it's to prevent the browser from showing a locally cached menu to the wrong user (i.e. if user logs out and logs back in a someone else using the same browser).