Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up JSON2 in piwik.js #6093

Closed
NekR opened this issue Aug 31, 2014 · 21 comments · Fixed by #15413
Closed

Clean up JSON2 in piwik.js #6093

NekR opened this issue Aug 31, 2014 · 21 comments · Fixed by #15413
Labels
duplicate For issues that already existed in our issue tracker and were reported previously.
Milestone

Comments

@NekR
Copy link

NekR commented Aug 31, 2014

Here:
https://github.com/piwik/piwik/blob/master/js/piwik.js#L45

You check for JSON2 object in window object which never exists and you always use JS version of JSON instead of builtin.

Also, here #6066 (comment) man said that you do not use json2.js, but you actually do, or at least json.js which is worse.

Refer to this commend for more details: #6066 (comment)

@mattab
Copy link
Member

mattab commented Aug 31, 2014

@mattab mattab closed this as completed Aug 31, 2014
@NekR
Copy link
Author

NekR commented Aug 31, 2014

what is JSON2? any link to standard?

@mattab
Copy link
Member

mattab commented Aug 31, 2014

@NekR
This place is our issue tracker, to keep track of bugs and feature requests. Please can you ask questions in the forums: http://forum.piwik.org/

@tsteur
Copy link
Member

tsteur commented Aug 31, 2014

We could actually indeed use builtin JSON API in case it exists.

JSON2 is a lib that we use as JSON API it is not supported by all browser see http://caniuse.com/#search=json

@halfdan
Copy link
Member

halfdan commented Aug 31, 2014

@NekR It's a polyfill/fix for broken JSON implementations in some older browsers.

@mattab @NekR has a valid point. Checking for JSON2 on the window object hardly makes any sense as we define JSON2.stringify and JSON2.parse later in the js file.

@NekR
Copy link
Author

NekR commented Aug 31, 2014

I knew what json2 is a pollyfill, but almost all browsers have builtin version.

So it's better to have

(function () {
    'use strict';

    if (window.JSON) {
        window.JSON2 = window.JSON;
        return;
    } else {
        window.JSON2 = {};
    }
   // ...

This is fast example how it should be. Or you can just replace everywhere word 'JSON2' to 'JSON'.

@tsteur
Copy link
Member

tsteur commented Aug 31, 2014

makes sense.

We could even think about removing JSON2 at some point completely. I just had a look and the browsers that do not support JSON builtin are less than 0.5% (IE7 has about 0.2%) and JSON is only needed when custom variables in scope visit are used anyway.

@halfdan halfdan reopened this Aug 31, 2014
@mattab
Copy link
Member

mattab commented Sep 1, 2014

@halfdan you reopened the issue, what do you think should be the scope? maybe Remove JSON2 from piwik.js or so?

@mattab mattab removed the worksforme label Sep 1, 2014
@halfdan
Copy link
Member

halfdan commented Sep 1, 2014

@mattab @NekR has shown an alternative solution that I find reasonable. We can also think about removing JSON2 completely if we decide that those 0.5% that @tsteur mentioned are not worth tracking anymore.

@mattab
Copy link
Member

mattab commented Sep 1, 2014

@halfdan could you rename ticket to clarify scope? then feel free to assign to Short term if it's a quick fix

@halfdan halfdan added this to the Short term milestone Sep 1, 2014
@halfdan halfdan changed the title JSON2 Clean up JSON2 in piwik.js Sep 1, 2014
@mattab mattab modified the milestones: Mid term, Short term Oct 12, 2014
@mattab mattab removed the Help wanted Beginner friendly issues or issues where we'd highly appreciate community's help and involvement. label Oct 12, 2014
@unwiredbrain
Copy link

How about using JSON 3 instead?

JSON 3 [...] is a drop-in replacement for JSON 2. [...] The JSON 3 parser does not use eval or regular expressions. This provides security and performance benefits in obsolete and mobile environments, where the margin is particularly significant.

The functions behave exactly as described in the ECMAScript spec, except for the date serialization [...] it does not define Date#toISOString() or Date#toJSON(). This preserves CommonJS compatibility and avoids polluting native prototypes. Instead, date serialization is performed internally by the stringify() implementation: if a date object does not define a custom toJSON() method, it is serialized as a simplified ISO 8601 date-time string.
-- http://bestiejs.github.io/json3/

Also, this will probably fix #5960.

@tsteur
Copy link
Member

tsteur commented Oct 15, 2014

Looking good to me. The minified version with 8kb is a bit a lot but should be still ok. Could go with this one for like a year and then support only builtin JSON.

Alternatively now or like in one year we would simply ignore browsers that do not support builtin JSON. If someone still wants those browsers tracked we could let it up to the user to load a separate file before that provides JSON2 or JSON3. So we would check if there is JSON, if not JSON2, then JSON3. If none is there we do not track on this very outdated browsers.

@mattab
Copy link
Member

mattab commented Oct 4, 2016

Increasing priority as we probably soon could remove JSON2 from piwik.js

@tsteur
Copy link
Member

tsteur commented Oct 4, 2016

It's currently pretty much only there for IE7 & IE6 see http://caniuse.com/#search=json

@mattab
Copy link
Member

mattab commented Dec 25, 2016

Ok so we won't remove this for a while since we need to support IE7 and IE6. Leaving opened, but decreasing priority

@mattab mattab modified the milestones: Backlog (Help wanted), 3.0.0 Backlog Dec 25, 2016
@mattab mattab removed the Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc. label Dec 25, 2016
@filipre
Copy link

filipre commented Aug 24, 2017

Any updates on this? I guess you are doing this due to contract duties but still encouraging the user to use IE6 sounds extremely insecure.

@mattab
Copy link
Member

mattab commented Sep 18, 2017

I guess you are doing this due to contract duties but still encouraging the user to use IE6 sounds extremely insecure.

we don't encourage users to use IE6, but we need to track users on IE6 and IE7 and cannot drop those users from tracking yet (we may in the future, though)

@Findus23
Copy link
Member

Would it be possible to drop the support for IE<7 in Matomo 4 and remove the JSON fallback from the piwik.js?

Now that plugins can modify the piwik.js it may be possible to write a plugin that adds JSON3 for those who still need it (and reducing the load time for everyone else)

Inspired by a forum post

@tsteur
Copy link
Member

tsteur commented Jan 30, 2018

👍 that is doable I'd say. A plugin that adds support for it may be doable as well.

Just a side note: JSON3 is currently also used for compatibility with some JS frameworks like older versions of prototype and others see eg #11023 .

@Findus23 Findus23 modified the milestones: Backlog (Help wanted), 4.0.0 Jan 30, 2018
@robocoder
Copy link
Contributor

@NekR: The reason piwik.js called it JSON2 (even though it was using json.js) was because some browsers provided broken window.JSON implementations.

That said, I'm all for dropping the polyfill for Matomo4.

@sgiehl
Copy link
Member

sgiehl commented Jan 25, 2020

fixed with #15413, will be included in Matomo 4

@sgiehl sgiehl closed this as completed Jan 25, 2020
@mattab mattab added the duplicate For issues that already existed in our issue tracker and were reported previously. label Sep 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate For issues that already existed in our issue tracker and were reported previously.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants