PHPackages                             components/jquery-cookie - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. components/jquery-cookie

AbandonedArchivedComponent[Utility &amp; Helpers](/categories/utility)

components/jquery-cookie
========================

A simple, lightweight jQuery plugin for reading, writing and deleting cookies

1.4.1.2(11y ago)4374.0k↓19.6%6MITJavaScript

Since Jun 28Pushed 11y ago1 watchersCompare

[ Source](https://github.com/Gta-Cool/jquery-cookie)[ Packagist](https://packagist.org/packages/components/jquery-cookie)[ Docs](https://github.com/carhartl/jquery-cookie)[ RSS](/packages/components-jquery-cookie/feed)WikiDiscussions feature/composer Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (4)Used By (6)

jquery.cookie [![Build Status](https://camo.githubusercontent.com/8ed31526a64fdb345c5c444a7b34e0dd35340e01763bc6c06b9d92b230ce6161/68747470733a2f2f7472617669732d63692e6f72672f636172686172746c2f6a71756572792d636f6f6b69652e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/carhartl/jquery-cookie) [![Code Climate](https://camo.githubusercontent.com/f9ebc54007afe76e9f109045d4a88caa50de6839253670d2f2b3355147e8acac/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f636172686172746c2f6a71756572792d636f6f6b69652e706e67)](https://codeclimate.com/github/carhartl/jquery-cookie)
================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#jquerycookie--)

A simple, lightweight jQuery plugin for reading, writing and deleting cookies.

**If you're viewing this at , you're reading the documentation for the master branch. [View documentation for the latest release (1.4.1).](https://github.com/carhartl/jquery-cookie/tree/v1.4.1)**

Build Status Matrix
-------------------

[](#build-status-matrix)

[![Selenium Test Status](https://camo.githubusercontent.com/4880d9cf6bbe8f702ad279a9e3f494eca429ca17fcb10abda23e9d5a2f788dd1/68747470733a2f2f73617563656c6162732e636f6d2f62726f777365722d6d61747269782f6a71756572792d636f6f6b69652e737667)](https://saucelabs.com/u/jquery-cookie)

Installation
------------

[](#installation)

Include script *after* the jQuery library (unless you are packaging scripts somehow else):

```

```

**Do not include the script directly from GitHub (...).** The file is being served as text/plain and as such being blocked in Internet Explorer on Windows 7 for instance (because of the wrong MIME type). Bottom line: GitHub is not a CDN.

The plugin can also be loaded as AMD or CommonJS module.

Usage
-----

[](#usage)

Create session cookie:

```
$.cookie('name', 'value');
```

Create expiring cookie, 7 days from then:

```
$.cookie('name', 'value', { expires: 7 });
```

Create expiring cookie, valid across entire site:

```
$.cookie('name', 'value', { expires: 7, path: '/' });
```

Read cookie:

```
$.cookie('name'); // => "value"
$.cookie('nothing'); // => undefined
```

Read all available cookies:

```
$.cookie(); // => { "name": "value" }
```

Delete cookie:

```
// Returns true when cookie was successfully deleted, otherwise false
$.removeCookie('name'); // => true
$.removeCookie('nothing'); // => false

// Need to use the same attributes (path, domain) as what the cookie was written with
$.cookie('name', 'value', { path: '/' });
// This won't work!
$.removeCookie('name'); // => false
// This will work!
$.removeCookie('name', { path: '/' }); // => true
```

*Note: when deleting a cookie, you must pass the exact same path, domain and secure options that were used to set the cookie, unless you're relying on the default options that is.*

Configuration
-------------

[](#configuration)

### raw

[](#raw)

By default the cookie value is encoded/decoded when writing/reading, using `encodeURIComponent`/`decodeURIComponent`. Bypass this by setting raw to true:

```
$.cookie.raw = true;
```

### json

[](#json)

Turn on automatic storage of JSON objects passed as the cookie value. Assumes `JSON.stringify` and `JSON.parse`:

```
$.cookie.json = true;
```

Cookie Options
--------------

[](#cookie-options)

Cookie attributes can be set globally by setting properties of the `$.cookie.defaults` object or individually for each call to `$.cookie()` by passing a plain object to the options argument. Per-call options override the default options.

### expires

[](#expires)

```
expires: 365

```

Define lifetime of the cookie. Value can be a `Number` which will be interpreted as days from time of creation or a `Date` object. If omitted, the cookie becomes a session cookie.

### path

[](#path)

```
path: '/'

```

Define the path where the cookie is valid. *By default the path of the cookie is the path of the page where the cookie was created (standard browser behavior).* If you want to make it available for instance across the entire domain use `path: '/'`. Default: path of page where the cookie was created.

**Note regarding Internet Explorer:**

> Due to an obscure bug in the underlying WinINET InternetGetCookie implementation, IE’s document.cookie will not return a cookie if it was set with a path attribute containing a filename.

(From [Internet Explorer Cookie Internals (FAQ)](http://blogs.msdn.com/b/ieinternals/archive/2009/08/20/wininet-ie-cookie-internals-faq.aspx))

This means one cannot set a path using `path: window.location.pathname` in case such pathname contains a filename like so: `/check.html` (or at least, such cookie cannot be read correctly).

### domain

[](#domain)

```
domain: 'example.com'

```

Define the domain where the cookie is valid. Default: domain of page where the cookie was created.

### secure

[](#secure)

```
secure: true

```

If true, the cookie transmission requires a secure protocol (https). Default: `false`.

Converters
----------

[](#converters)

Provide a conversion function as optional last argument for reading, in order to change the cookie's value to a different representation on the fly.

Example for parsing a value into a number:

```
$.cookie('foo', '42');
$.cookie('foo', Number); // => 42
```

Dealing with cookies that have been encoded using `escape` (3rd party cookies):

```
$.cookie.raw = true;
$.cookie('foo', unescape);
```

You can pass an arbitrary conversion function.

Contributing
------------

[](#contributing)

Check out the [Contributing Guidelines](CONTRIBUTING.md)

Authors
-------

[](#authors)

[Klaus Hartl](https://github.com/carhartl)

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community24

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 81.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

3

Last Release

4338d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f17ac1b85aed68558af16d81576f9da49dbba42ebbf2d2bf021356981919c9ce?d=identicon)[Gta-Cool](/maintainers/Gta-Cool)

---

Top Contributors

[![carhartl](https://avatars.githubusercontent.com/u/21918?v=4)](https://github.com/carhartl "carhartl (171 commits)")[![FagnerMartinsBrack](https://avatars.githubusercontent.com/u/835857?v=4)](https://github.com/FagnerMartinsBrack "FagnerMartinsBrack (21 commits)")[![kswedberg](https://avatars.githubusercontent.com/u/3485?v=4)](https://github.com/kswedberg "kswedberg (3 commits)")[![Gta-Cool](https://avatars.githubusercontent.com/u/565072?v=4)](https://github.com/Gta-Cool "Gta-Cool (2 commits)")[![wilmoore](https://avatars.githubusercontent.com/u/51953?v=4)](https://github.com/wilmoore "wilmoore (2 commits)")[![BrunoWinck](https://avatars.githubusercontent.com/u/4559776?v=4)](https://github.com/BrunoWinck "BrunoWinck (1 commits)")[![guybedford](https://avatars.githubusercontent.com/u/598730?v=4)](https://github.com/guybedford "guybedford (1 commits)")[![MrNice](https://avatars.githubusercontent.com/u/2587335?v=4)](https://github.com/MrNice "MrNice (1 commits)")[![tomkins](https://avatars.githubusercontent.com/u/177332?v=4)](https://github.com/tomkins "tomkins (1 commits)")[![vlakoff](https://avatars.githubusercontent.com/u/544424?v=4)](https://github.com/vlakoff "vlakoff (1 commits)")[![gaastonsr](https://avatars.githubusercontent.com/u/2997285?v=4)](https://github.com/gaastonsr "gaastonsr (1 commits)")[![bunnymatic](https://avatars.githubusercontent.com/u/427380?v=4)](https://github.com/bunnymatic "bunnymatic (1 commits)")[![colinrymer](https://avatars.githubusercontent.com/u/724007?v=4)](https://github.com/colinrymer "colinrymer (1 commits)")[![coryschires](https://avatars.githubusercontent.com/u/104563?v=4)](https://github.com/coryschires "coryschires (1 commits)")[![duncansmart](https://avatars.githubusercontent.com/u/576343?v=4)](https://github.com/duncansmart "duncansmart (1 commits)")

---

Tags

javascriptJSjquerycookie

### Embed Badge

![Health badge](/badges/components-jquery-cookie/health.svg)

```
[![Health](https://phpackages.com/badges/components-jquery-cookie/health.svg)](https://phpackages.com/packages/components-jquery-cookie)
```

###  Alternatives

[matthiasmullie/minify

CSS &amp; JavaScript minifier, in PHP. Removes whitespace, strips comments, combines files (incl. @import statements and small assets in CSS files), and optimizes/shortens a few common programming patterns.

2.0k30.5M336](/packages/matthiasmullie-minify)[snapappointments/bootstrap-select

The jQuery plugin that brings select elements into the 21st century with intuitive multiselection, searching, and much more. Now with Bootstrap 4 support.

9.8k480.4k3](/packages/snapappointments-bootstrap-select)[nostalgiaz/bootstrap-switch

Turn checkboxes and radio buttons into toggle switches.

5.0k362.3k4](/packages/nostalgiaz-bootstrap-switch)[froala/wysiwyg-editor

A beautiful jQuery WYSIWYG HTML rich text editor. High performance and modern design make it easy to use for developers and loved by users.

5.4k306.9k3](/packages/froala-wysiwyg-editor)[onokumus/metismenu

A jQuery menu plugin

2.0k263.3k5](/packages/onokumus-metismenu)[yajra/laravel-datatables-html

Laravel DataTables HTML builder plugin

2899.6M48](/packages/yajra-laravel-datatables-html)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
