Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is writing a cookie very slow in JS?

I need to make my website faster on the client side. I wonder if my excessive Javascript cookie manipulation could slow down the browser. It uses the harddrive, which is the slowest component of a computer. On a severely fragmented harddrive, could cookie manipulation freeze the browser?

Is JS doing any optimizations for cookie writing/reading (caching, etc..). Could I exploit these optimizations to improve my site?

Replacing client-side cookies with a server side database is out of the question because my servers are overloaded already.

like image 494
JoJo Avatar asked Sep 27 '10 22:09

JoJo


People also ask

Can JavaScript write cookies?

JavaScript can create, read, and delete cookies with the document.

Do cookies make page load faster?

Cookie data stacks up pretty quickly, taking up browser memory space. The cache stores your data from websites so the pages load faster on future visits.

Is JavaScript the same as cookies?

HTTP Cookies are not a feature of PHP, nor a feature of Javascript : those are just programming languages that allow a developper to manipulate them. The biggest difference between JS and PHP is that : Javascript runs on the client side. PHP runs on the server side.

Why do you need a cookie in JavaScript?

A cookie is an amount of information that persists between a server-side and a client-side. A web browser stores this information at the time of browsing. A cookie contains the information as a string generally in the form of a name-value pair separated by semi-colons.


1 Answers

There are a few ways you can speed up your page on the client side, although I'm guessing reducing cookie use would only save a few microseconds at best. Just in general make sure you are only saving what you need.

There are tons of other optimizations that you can do though, such as:

  • Serving your files as gzipped content
  • Ensuring as much of your site is cache-able
  • Using CSS sprites and combining javascript + css files to reduce HTTP requests (will reduce load from your server too)
  • Minifying your javascript, css and html

These are all proven methods of reducing page load times.

For more information on how to make your page load faster, get the YSlow! plugin for firefox / firebug http://developer.yahoo.com/yslow/

like image 184
Randy the Dev Avatar answered Oct 14 '22 08:10

Randy the Dev