Hi everyone, first time posting here.
[SIZE=4]The problem:
I’ve got a messy site that I’m supposed to make faster and a big culprit seems to be the way it’s handling session values. Right now it has a bunch of functions like GetDeliveryType() and SetDeliveryType() and instead of retrieving the values once, it will do GetDeliveryType() every single time that value is needed in the code. The problem is these are doing [B]synchronous
[CODE]
function SetDeliveryType(p_deliverytype) {
$.ajax({
type: “GET”,
url: “/cart/setCartDeliveryType”,
data: { deliverytype: p_deliverytype },
async: false,
success: function (response) {
//stores = JSON.parse(response);
//alert(response)
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(“Exception in /order/SetDeliveryType : ” + errorThrown);
}
});
}
So I have blocking ajax calls everywhere firing potentially dozens of times per page load. As you might guess, this is horribly slow.
[SIZE=4]
The solution?
I’m a junior developer and I’m having a hard time finding info on the best way to solve this. Ideally I would like to
1. Do away with all the ajax calls, just set the variables as global or near global js variables and access everything in native code. Is that possible? Or will I get stuck with no way to access them when the user goes to the next page or some other caveat?
failing that I would like to
2. Get values only once and then store them as variables and access them in native code. Is that viable?
or
3. Session storage or local storage? How would that work?
Whatever the right way to approach this is, could I also get a few pointers on how to set it up and get started? It would be much appreciated.