I have 3 JSP views which all use the same JS file(say app.js).
My UI is on AngularJS which has a different controller for each of the JSP views and also has a custom service which shares information between the controllers. When I load the first JSP, its controller specified in the app.js file saves a value in the custom service. When I load the next JSP file, app.js gets reloaded and so the value that was saved in the custom service is lost.
Is there a way to not re-load JS files? Or is there a better way to go about this?
You have different ways to deal with this persistence between page question. One way is server side by using the session:
An alternate way is the single page application pattern:
Additionally, you could use
Windows.sessionStorage to store data client side for the duration of a client session - credits should go to @AmitParashar for this one, more details in his answer.
A less common pattern (AFAIK) is to put the state in a cookie. That way it can be shared by the server and the client but: