Posts

Showing posts with the label #javascript

Caching mechanisms in modern world browser

Image
           Getting data locally is always faster than the getting data from server. There are different types of caching mechanism that can be used to cache data on browser for optimizing performance and faster data retrieval. We will see some of the data store that can be used on client to cache or store data. 1. Session Storages     This is a very well-known storage on browser. Commonly uses to session specific data on this store. We can infer a current tab as one session. Session storage will not be available across tabs or new tab. Maximum limit of of session storage is 5MB.     Limitations:     It cannot use to persist information across tab or sessions     It cannot store data more than 5MB.     Data is not secure. Additional effort need to secure data stored 2. Local storage     Local storage is also a very well-known storage. This is u...

How to do AJAX using XMLHttpRequest for large data

Your are at right place if you are : working on loading huge amount of data from server be it JSON or XML document getting truncated JSON Response string  observing $.ajax call failure due to JSON.parse is compiling about invalid char while parsing JSON  observing performance lag while parsing JSON using $.ajax observing response code 200 but there is not response received in $.ajax success call  Uncaught InternalError: allocation size overflow in $.ajax If you are loading large data from server then you need to consider lot of factors impacting load time. There can be optimization on server as well as client. Coming to client, most commonly used API for AJAX is JQuery.ajax. But when it comes to fetching large data set from server be it in JSON format or XML document, you might end up facing issue mentioned at the beginning of this blog. I observed that in case of large JSON String in response, response string is being truncated. Also, if string is not truncated, JSON.par...

Null, undefined and empty checks in JavaScript

Whenever you are writing code in Javascript, the Most common point comes where you and your code reviewer comes to a point to write fail-safe code. When we are talking about fail-safety, the prominent use case comes to check null, undefined, and empty text values. It is very important to handle these values in order not to come across a code failure at runtime. If there are use cases where your variables attain null or undefined you will be in a position to understand and handle it. In JavaScript, the state with no value is represented by  null   or  undefined . It is one of the  primitive values . The most common way to handle the null value is to just put the variable in if condition check. var myVariable = null; //typeof null is "object" and treated falsy if(myVariable){ //resolves to false as value is null console.log(‘I will not print if the value is null.’); } Similar to null, undefined is also treated as falsy. The difference between undefined and null...