In any case, please don't worry about these kinds of micro-optimizations. JS engines change all the time and what was slow becomes fast; and workarounds to try to optimize almost always lead to worse code.
Even in the best case, you're talking about an operation that runs only once per route change; and at its slowest, the JS engine can execute this over a million and a half times a second; ie, this is not an actual bottleneck by any stretch of the imagination.
This is actually slower.
In any case, please don't worry about these kinds of micro-optimizations. JS engines change all the time and what was slow becomes fast; and workarounds to try to optimize almost always lead to worse code.
Even in the best case, you're talking about an operation that runs only once per route change; and at its slowest, the JS engine can execute this over a million and a half times a second; ie, this is not an actual bottleneck by any stretch of the imagination.