Monday, March 13, 2017

What is the difference between Local Storage and Cookies

Hi Friends,

In this post we are going to talk about when to use Local storage and Cookies.

To begin with, this is an extremely broad scope question, and a lot of pros/cons will be contextual to the situation.

Please find the below differences.


Local Storage
Cookies
Good to store large amount of data, up to 4MB
Good for small amount of data.
Cookies give you a limit of 4096 bytes (4095, actually) per cookie
Local Storage allow you to store JavaScript primitives but not Objects or Arrays (it is possible to JSON serialize them to store them using the APIs)
Cookies only allow you to store strings
Local storage data is not sent to the server on every request (HTTP header) as it is purely at the client side
All data is transferred to and from server, so bandwidth is consumed on every request
It stores data with no expiration date, and gets cleared only through JavaScript, or clearing the Browser Cache / Locally Stored Data
Can specify timeout period so that cookies data are removed from browser
Local storage stores the data in the form of key and value

Not supported by anything before: IE 8, Firefox 3.5, Safari 4, Chrome 4, Opera 10.5, iOS 2.0, Android 2.0
local storage can only be read client-side



Hope this helps...

Friday, March 10, 2017

When to use ScriptLink in SharePoint 2013

Hi Folks,

Some times we will run into situations where our custom js file should load only after the page is ready.

In this kind of scenario's, best thing to use is ScriptLink.

ScriptLink have the ability to specify, when we want the script to load asynchronously after the page is ready. By Default, the ScriptLink will always look for the scripts present in /_LAYOUTS/1033 folder.

<SharePoint:ScriptLink language="javascript" name="MyCustomJS.js" Defer="true" runat="server"></SharePoint:ScriptLink>

MyCustom.js should be present in /_LAYOUTS/1033 folder, if not we will get a SharePoint Error screen.

If you set the "Localizable" property of the ScriptLink to false, you can also reference files outside of /_LAYOUTS/1033/ and just put your path to the "Name" property

<SharePoint:ScriptLink Language="javascript" Localizable="false" Name="/_layouts/JS/MyCustomJS.js" runat="server"></SharePoint:ScriptLink>

With the above approaches, we can load the page first and then load the script file.

Note: Using Defer="False" is basically the same as loading the script with the usual method as below.
<script type="text/javascript" src="/_layouts/1033/MyCustomJS.js"></script>


Hope this helps...

Wednesday, March 8, 2017

Why Javascript works only after launching developer tool bar in IE once

Hi Friends,

This post basically talks about the strange experience which I faced in one of the applications.

Problem Statement:
In Internet Explorer, the Javascript/jQuery is not working until I open the IE Tool bar once.


Solution:
After multiple trial and errors, what I observed is, it's because of the console.log present in my jQuery file.

The console object will only be activated when the IE Dev Toolbar is opened. Prior to that, calling the console object will result as undefined. After the toolbar has been opened, the console will exist (even if the toolbar is subsequently closed), so your console calls will then work.


Hence make sure to remove any Console entries from the JS file during the roll-out of the application.


Hope this helps...

Popular Posts