cancel
Showing results for 
Search instead for 
Did you mean: 

Jquery Cookie

Jquery Cookie

Feature request from minhluan259, posted on GitHub Jun 16, 2016

pub/static/frontend/Magento/luma/en_US/jquery/jquery.cookie.js Jquery cookie in magento 2.1 is old version (v1.1). It hasn't function $.removeCookie.

Please update to jquery cookie v1.4.1 https://github.com/carhartl/jquery-cookie/blob/master/src/jquery.cookie.js

8 Comments
New Member

Comment from orlangur, posted on GitHub Jun 16, 2016

Why this update is needed in core? I don't see removeCookie used anywhere. Are there any bugs you observe with existing version?

As I can see from https://github.com/carhartl/jquery-cookie/releases, this plugin is abandoned since April 2014, so, I would rather upgrade to a newer library version which does not even require jQuery anymore.

But, again, what would be the value of such update for the core? If you ever need removeCookie in your custom project or extension, you can just easily replace js file with another backward-compatible version.

New Member

Comment from minhluan259, posted on GitHub Jun 16, 2016

I don't want to use an external library. I want use an existing library in magento, but jquery cookie is too old. Can you tell me what's the newer library you want use?

New Member

Comment from orlangur, posted on GitHub Jun 17, 2016

In this link https://github.com/carhartl/jquery-cookie/releases the top item point to "To see all the versions, check the new repository."

For your needs, if you just need removeCookie functionality, I suggest to replace jquery cookie to v 1.4.1 in your custom project/extension or use a newer library.

New Member

Comment from FagnerMartinsBrack, posted on GitHub Jun 18, 2016

There were some breaking changes in jquery-cookie with a minor bump instead of major (they can be seen in the changelog), but since v1.4.1 we started following semver strictly and v1.5.1 is totally backwards compatible with v1.4.1.

The changelog is very clear, if you guys need any help to upgrade just ping me.

New Member

Comment from adragus-inviqa, posted on GitHub Jun 22, 2016

The jquery storageapi plugin itself comes bundled with jquery.cookie 1.3.1, not 1.1, as M2 currently has: https://github.com/julien-maurel/jQuery-Storage-API/blob/1.7.3/Jasmine/lib/jquery.cookie.js

So it's like this:

  • GitHub
    • jquery.storageapi 1.7.3
      • jquery.cookie 1.3.1
  • Magento 2
    • jquery.storageapi 1.7.3
      • jquery.cookie 1.1 <--- breaks because of this

@orlangur

Why this update is needed in core? I don't see removeCookie used anywhere.

  • Yeah, because there is no such method. jquery.cookie 1.1 doesn't have it; 1.3.1 does.
  • Not sure it's a legit question. No one can do jQuery.cookieStorage.remove('some_cookie') in Magento 2: you get a jquery.storageapi.min.js:formatted:283 Uncaught TypeError: e.removeCookie is not a function error. Only isSet, set, get etc. work. Maybe that's the reason you haven't seen it yet: it breaks. If this is a "no problem" scenario...

Better bump jquery.cookie to 1.3.1.

New Member

Comment from adragus-inviqa, posted on GitHub Jun 22, 2016

@minhluan259 - use mage/cookies instead:

define([
    'jquery',
    'mage/cookies'
], function($) {
    "use strict";

    $.mage.cookies.get();
    $.mage.cookies.set();
    $.mage.cookies.clear();
});

It's simple and it does the job: https://github.com/magento/magento2/blob/3561b6614eeafb70cbcbf0dc0254359b857af3d4/lib/web/mage/cooki...

The question now is what to use. Too many options...

New Member

Comment from minhluan259, posted on GitHub Jun 24, 2016

Thank you @adragus-inviqa. I have tryed $.mage.cookies.set('name', 'value'); but it doesn't create session cookie, it auto add expires, not good like Jquery Cookie.

New Member

Comment from adragus-inviqa, posted on GitHub Jun 24, 2016

@minhluan259 - well, you can use options.lifetime: $.mage.cookies.set('name', 'value', {lifetime: 342342342342})