Posts

Showing posts from 2016

Symfony - How to avoid browser caching assets even after production deployment.

All Browsers have some caching mechanism, they cache most of the css, javascript and images those are loaded frequently from an website. However, this might be a headache for a developer when they made changes to some of the JS, CSS but the changes are not reflected in website, unless you clear the local cache. The global standard is to change the file path name or add a query parameter to your asset as such : 1 example.com / assets / css / common.css ? v = 234 So to implement this Symfony framework supplies a straight forward solution in its asset configuration. It's called assset version . Just add below configuration to your config.yml and rest will be taken care by Symfony framework when it loads an asset to the template. 1 2 3 4 # config.yml framework: assets: version : 'v1451' The above settings is not limited to twog templates, If your application serves APIs and your response is in JSON or XML format, the above settings will als...

Javascript - Local Storage with expiry options.

Most of the time, a local storage in HTML5 browsers is helpful to cache content from server for a certain period, Be it a dynamic menu, a big json data or a complex javascript object. All it need is to store in local storage for a certain period, collect data from local storage without hitting server again and again. But when the caching time lapses, the content should be retrieved fresh from the server. Below is a Javascript object which should be pretty much helpful to store and retrieve content in local storage with an optional time limit, expiring which, the returned value will be null instead, prompting us to get fresh data and store again. Moreover, it saves javascript objects to localstorage, with a certain prefix to identify object ( "_|_obj_|_" ), so that it can parse the value at the time of storing and retrieving the object var localStorageObj = { init : function () { this .$timeSuffix = "_lu" ; this .$expiryDuration = 1...