Improve frontend javascript