Should the caching of WordPress menus be specific to each page?
There is no generic solution for this problem: The same menu can be rendered with different walkers on different pages, or plugins change the menu on some pages. You could extend your script to evaluate the differences to an untouched menu and build the necessary JavaScript on the fly … and cache that too … … Read more