Ticket #757 (closed enhancement: fixed)

Opened 18 months ago

Last modified 14 months ago

add removeOptionCookie() function to core

Reported by: EricShulman Owned by: JeremyRuston
Priority: minor Milestone: 2.4.3
Component: core Version:
Severity: low Keywords:
Cc:

Description (last modified by EricShulman) (diff)

The core function, saveOptionCookie(), creates a browser cookie that stores the current value of the specified option. However, when an option is reset to it's hard-coded default value, rather than removing the cookie, it is usually just set to that default value, which results in an accumulation of unnecessary cookies.

Unfortunately, there is a browser-imposed limit on the number of cookies that are stored for any given domain and, when that limit is reached, the browser starts discarding cookies on it's own, thereby unexpectedly losing some TW settings.

In order to allow core and/or plugin code to 'clean up after themselves' and remove unneeded cookies, the core should provide a function, removeOptionCookie() that is the inverse of the existing saveOptionCookie(), and results in the actual deletion of the associated browser cookie.

window.removeOptionCookie=function(cookie) {
	var ex=new Date();
	ex.setTime(ex.getTime()-1000);  // immediately expire cookie
	document.cookie = cookie+"=novalue; path=/; expires="+ex.toGMTString();
}

Note: this approach is currently being used by several TiddlyTools plugins and scripts. For example, NestedSlidersPlugin? only creates a cookie to track a slider's opened/closed condition if that slider is currently in it's non-default state (i.e., an open slider that starts out closed, or a closed slider that starts out opened). When the slider is returned to it's default state, the corresponding tracking cookie is completely *removed* (as opposed to simply setting it's value to "false"), thereby minimizing the number of active cookies being used to track sliders.

Also note that this proposal is only to add the core utility function... it would then still remain up to the individual bits of core and/or plugin code to actually start using this function to remove some of their cookies as appropriate.

Change History

Changed 18 months ago by EricShulman

  • description modified (diff)

Changed 17 months ago by FND

[original comment by JeremyRuston?]

I've incorporated a fix for this ticket in the patch I've posted for ticket #756

Changed 16 months ago by EricShulman

  • milestone set to 2.5

This ticket is related to  http://trac.tiddlywiki.org/ticket/756 ("persistent settings without cookies")... if #756 doesn't go out in the next release, then this ticket will still allow JUST the removeCookie() function to be added to the core as soon as possible, so that plugin developers can start using it to clean up their left over cookies.

Also, for consistency with the #756 patch code already submitted, the function will be named removeCookie(), not removeOptionCookie(), and has also been optimized by using a hard-coded expiration date instead of calculating one each time. Thus:

window.removeCookie=function(name) {
	document.cookie = name+'=; expires=Thu, 01-Jan-1970 00:00:01 UTC; path=/;'; 
}

Based on discussion in the "Developer's Conference Call" of Nov 10, 2008, this ticket should remain open until a determination is made about when the #756 patch will be released.

Changed 14 months ago by FND

  • status changed from new to closed
  • resolution set to fixed
  • milestone changed from 2.5.1 to 2.4.3

Fixed in changeset:8368

Note: See TracTickets for help on using tickets.