I believe that I've made a terrible mistake. I have a global JS file that I include via script tag on every single JSP page.
<script type="text/javascript" src="/myGlobalJS.js" ></script>
In that JS file I make a call to get JSON; but I only want that executed once. Right now it executes every time a new JSP page loads.
var myObj = (function(){
var myData = {};
return{
setData:function(data){
myData = data.response;
}
};
})();
(function(){
$.getJSON(jsonUrl)
.done(function(data){
myObj.setData(data.response.data);
});
})();
How can I correct this elegantly?
Update: I can see the error of my thinking now. I'm thinking about these JSP pages as an application and when the app loads then it should execute getting this JSON file only one time. There is no persisted UI state across these JSP pages. So I think that I'll have to load the file and call it on every page I need it, unfortunately. Is this true?