Every site should have a script like web.archive.org/__cleancookies__.html
Posted by jpluimers on 2021/06/02
I run in too many sites that keep creating new cookies, but never delete the old ones, ultimately leading to 5xx errors.
Every site should have a page like [WayBack] web.archive.org/cleancookies.html that cleans non-current cookies.
So I copied toe source to [WayBack] Copy of https://web.archive.org/cleancookies.html · GitHub for inspiration to look at.
–jeroen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <body> | |
| <script type="text/javascript"> | |
| var DONT_DELETE = { | |
| "logged-in-sig": 1, | |
| "logged-in-user" : 1, | |
| }; | |
| var cookies = document.cookie.split(/; */); | |
| var result = {}; | |
| var cookie_count = 0; | |
| for (var i = 0; i < cookies.length; i++) { | |
| var kv = cookies[i].split(/=/); | |
| if (kv.length >= 2) { | |
| var name = kv[0]; | |
| if (DONT_DELETE[name]) { | |
| result[name] = { action:'kept' }; | |
| } else { | |
| document.cookie = name + "=; domain=.archive.org; path=/; max-age=0"; | |
| document.cookie = name + "=; domain=web.archive.org; path=/; max-age=0"; | |
| document.cookie = name + "=; path=/; max-age=0"; | |
| result[name] = { action: 'deleted' }; | |
| cookie_count++; | |
| } | |
| } | |
| } | |
| cookies = document.cookie.split(/; */); | |
| for (i = 0; i < cookies.length; i++) { | |
| var kv = cookies[i].split(/=/); | |
| if (kv.length >= 2) { | |
| result[kv[0]].still_there = true; | |
| } | |
| }</script> | |
| <div>Done.</div> | |
| <script type="text/javascript"> | |
| if (cookie_count > 0) { | |
| document.write("<ul>"); | |
| for (name in result) { | |
| var r = result[name]; | |
| if (r.action == 'kept') { | |
| document.write("<li><code>" + name + "</code> (kept)</li>"); | |
| } else if (r.still_there) { | |
| document.write("<li><code>" + name + "</code> (could not delete)</li>"); | |
| } else { | |
| document.write("<li><code>" + name + "</code> (deleted)</li>"); | |
| } | |
| } | |
| document.write("</ul>"); | |
| } else { | |
| document.write("<div>You had no cookies to delete. Hooray!</div>"); | |
| } | |
| </script> | |
| </body> | |
| </html> |
Rate this:
Share this:
- Share on Mastodon (Opens in new window) Mastodon
- Share on Bluesky (Opens in new window) Bluesky
- Share on Tumblr
- Share on Reddit (Opens in new window) Reddit
- Share on Threads (Opens in new window) Threads
- Tweet
- Share on Telegram (Opens in new window) Telegram
- Share on Nextdoor (Opens in new window) Nextdoor
- Share on WhatsApp (Opens in new window) WhatsApp
- Print (Opens in new window) Print
- Email a link to a friend (Opens in new window) Email
Related
This entry was posted on 2021/06/02 at 12:00 and is filed under Development, Power User, Software Development, Web Development. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
This site uses Akismet to reduce spam. Learn how your comment data is processed.






Leave a comment