Is it possible to save a whole website in a cookie. For example I have a website with some div´s i can move. And I want to write the text change the size of the div and possition. Is it possble to save the whole code in a cookie ?
-
1Why would you want to do that? A quick search shows a cookie is limited in size: http://stackoverflow.com/q/640938/1909061. Besides that, you can put what you want in there. It's probably *not* what you want though. Google for session and local storage which will point you in a better direction. – evilham Dec 03 '16 at 03:05
-
Session storage & local storage would be better to use. I was thinking about those too. It sounds like the only things that need to be cookied are the text + the size + the position's X & Y coordinates. The entire website's HTML markup doesn't need to be cookied, but just those 4 data points for each draggable div which is on the page. – Clomp Dec 03 '16 at 03:17
1 Answers
According to the Mozilla MDN Notes section on cookies, it should be possible to do, but it's a VERY, VERY BAD IDEA to do it. Users can have cookies blockers, which will prevent the website from being saved into the cookie.
See the spec at: https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie
RFC 2965 (Section 5.3, "Implementation Limits") specifies that there should be no maximum length of a cookie's key or value size, and encourages implementations to support arbitrarily large cookies. Each browser's implementation maximum will necessarily be different, so consult individual browser documentation.
Here are some links on cookie size limitations:
http://webdesign.about.com/od/cookies/f/web-cookies-size-limit.htm http://browsercookielimits.iain.guru/
If you want to support most browsers, then don't exceed 50 cookies per domain, and don't exceed 4093 bytes per domain (i.e. total size of all cookies <= 4093 bytes)
If you try it & your website's code goes over 4093 bytes, it won't fit! I don't recommend trying it!