Tuesday, December 29, 2015

Disable browser caching



1- Modify URL of JavaScript or CSS resources by adding to it  queryString with unique thing that can not be duplicated like ("?"+Math.Random() ) or ("?" + new Date().getTime()")
so every time page loaded , URL of resource will be appear for browser as a new URL so it will made a new request to get copy of resource .

i made a JavaScript function for loading script with feature option to enable caching or disabled it 

function loadJS(url, options) {

            var scriptElement = '<scr' + 'ipt src="' + url;

                if (options != null && options.CachingEnabled != null && !options.CachingEnabled) {
                    scriptElement += '?' + Math.random(); // or new Date().getTime()
                }

            scriptElement += '" type="text/javascript"></scr' + 'ipt>';
            document.write(scriptElement);
        }

and then we can call it like below 
 loadJS("env.js", { CachingEnabled: false });

references for this solution: 



2- I know you wont to use jQuery but if you made any request to server that will made ajax call by using jQuery ajax methods 
and need to disable caching on ajax requests it will apply prev solution with alternative thing that supported from jQuery  (property cach : false)

references for this solution: 


3- Disabling Caching with .htaccess file that will be supported with Apache server 

<filesMatch "\.(js|css)$">
FileETag None
<ifModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</ifModule>
</filesMatch>
 
references for this solution :
htaccess file no cache
Disabling Caching with .htaccess

Mapping Json Structure to another Json Structre



sample


ID = ID
incidentStatus.color= StatusColor
incidentPriority.type= PriorityType
flags[i].additionalDataConfiguration.iconURL = ADS[i].IconURL
flags[i].additionalDataConfiguration.type.name = ADS[i].Name


we need to map

var json1 = {
ID = 1
item.color= 'red'
item.type= 'high'
flags[i].details12.iconURL = "www.google.com"
flags[i].additionalXY.type.name = "name"
}

to be

var json2= {
id = 1
itemDetails.color= 'red'
item.type= 'high'
de[i].details12.iconURL = "www.google.com"
de[i].additional12.type.name = "name"
}





1 1-      json2json-master



2  2-      demo_jsonpath-object-transform