ClassicPress / ClassicPress-v1

A copy of ClassicPress v1.x.
1 stars 1 forks source link

Move from jQuery to vanilla JS #131

Closed C-Lodder closed 1 year ago

C-Lodder commented 5 years ago

Having looked at your browser requirement (>= IE11), I think it would be a great opportunity to start moving away from jQuery. This will give ClasicPress a great performance boost over WP

Thoughts?

nylen commented 5 years ago

I don't use jQuery anymore for new projects, but there is still a very large amount of jQuery code in ClassicPress core alone.

A much bigger hurdle here would be backwards compatibility with plugins and themes. Since jQuery has been available for so long, basically every add-on developer assumes it's available and uses it.

I would suggest starting a petition for this issue at https://petitions.classicpress.net/ to gauge interest, and then starting to map out what would be needed in order to achieve this with a reasonable path forward for backwards compatibility.

C-Lodder commented 5 years ago

I think maybe there might be a little confusion. I'm not saying remove the actual jQuery file from core as there may be some plugins out there that use it. I'm saying rewrite all the core Javascript that relies on jQuery in vanilla JS. Keeping the actual file will prevent any 3rd party plugin B/C breaks

Remzi1993 commented 5 years ago

@nylen We could give the user an option to select/activate a particular jQuery version or turn it off completely like I did with my plugin: https://github.com/Remzi1993/jquery-manager

For example:

C-Lodder commented 5 years ago

@Remzi1993 The use of jQuery should be up to plugin developers, e.g if you call:

wp_enqueue_script('my-custom-script', get_template_directory_uri() .'/js/my-custom-script.js', array('jquery'), null, true);

It will load jQuery automatically along with the script you called.

I don't think an option to disable/enable it is a good call at all.

nylen commented 5 years ago

I think maybe there might be a little confusion. I'm not saying remove the actual jQuery file from core as there may be some plugins out there that use it. I'm saying rewrite all the core Javascript that relies on jQuery in vanilla JS. Keeping the actual file will prevent any 3rd party plugin B/C breaks

Yes, I understand that.

there may be some plugins out there that use it

This is a huge understatement.

Plugins and themes should declare a dependency on jquery in their scripts, but I bet not all of them do.

So here are two action items for this task:

C-Lodder commented 5 years ago

@nylen This has nothing to do with how many plugins use jQuery. All I'm saying is that the core JS scripts that are used for ClassicPress should simply be rewritten.

This isn't a new feature. It's an enhancement

Remzi1993 commented 5 years ago

@C-Lodder The reason why I mention this idea/possible solution is because most users don't need jQuery Migrate, also jQuery 1.x and jQuery 2.x are officially not supported anymore. I know that the WP team and others have backported bug fixes and security updates, but this isn't ideal.

WP wants to move to jQuery 3.x eventually, but this will take time. See: https://core.trac.wordpress.org/ticket/37110

We could move to jQuery 3.x and provding backwards compatibily with providing users the option to select the version they need or turn it off or on with a simple switch.

C-Lodder commented 5 years ago

@Remzi1993 I would have thought the vision would be to move away from jQuery in the core product as opposed to a roadmap for updating to v3.0.

I mean, it's taken them 3 years so far and it's still no complete.

jQuery was originally there to solve browser compatability issues, but as your using IE11, it really isn't needed as much as you think it is.

Remzi1993 commented 5 years ago

@C-Lodder I know, but I think they want to move to jQuery 3.x because most devs are used to writing jQuery code rather than vanilla. Browser compatibility is still a thing if you want to support IE 11 (extra code) and most of the times the code is shorter/cleaner than vanilla.

C-Lodder commented 5 years ago

I know, but I think they want to move to jQuery 3.x because most devs are used to writing jQuery code rather than vanilla

And they can still write their jQuery even if the core doesn't use it.

most of the times the code is shorter/cleaner than vanilla.

It may be shorter, but the performance is terrible.

Remzi1993 commented 5 years ago

@C-Lodder You're right. Everything should be in vanilla (at least on our side/1st party), but you need to give 3rd party devs the option to use jQuery, otherwise they will eventuality include their own versions and this could collide with each other.

Edit: remember that a lot of (old) plugins use jQuery, they could fix some compatibility issues after we have updated jQuery, but they will not rewrite their entire codebase just because we decide we don't want jQuery.

C-Lodder commented 5 years ago

but you need to give 3rd party devs the option to use jQuery

As I said before, we're not taking away the option for them to use jQuery. This will not effect them in any way at all. They can continue developing plugins in exactly the same way.

Remzi1993 commented 5 years ago

@C-Lodder So just the be precise, you're advocating only for that we should move to vanilla (ClassicPress code/1st party) and that we should give 3rd party dev the option if they want to use jQuery or not?

If so, I'm with you and this would be a lot of work. We also should consider which browsers we should support if this happens.

C-Lodder commented 5 years ago

@Remzi1993

you're advocating only for that we should move to vanilla (ClassicPress code/1st party)

yes

that we should give 3rd party dev the option if they want to use jQuery or not?

Not an option like a checkbox, but they simply continue writing their plugins using jQuery or can use vanilla JS. Entirely up to them.

We also should consider which browsers we should support if this happens.

Well if it were up to me, I'd drop IE support completely and start looking at the future. But that's just me

Remzi1993 commented 5 years ago

Well if it were up to me, I'd drop IE support completely and start looking at the future. But that's just me

Me too, but IE11 is still officially supported by Microsoft (rumor has it that it is only supported until Windows 7- January 14, 2020)

I would like to what @nylen thinks about this. Which browsers should we support? Including IE or not? Or only so called "evergreen browser" (browsers that are automatically upgraded to future versions, like for example Chrome, Firefox and Opera)

ginsterbusch commented 5 years ago

TL;DR: Skipping fast forward - Native JS would be nice, but jQuery still solves a lot of issues, essentially working as an "unificator" or "unifying API". Hence why lots of web designers or more frontend DESIGN-oriented folks tend to use it over "complicated" normal JS. A major part of WPs success is the fact that you didnt need to be a natively bred and born frontend developer to get a site for a client built and done.

Also, lets not forget about the Admin backend, which relies heavily on jQuery being around.

Onto the next topic: "Browser support" is a major PITA - that is also one of the reason to keep jQuery (preferably in version 3) around: It solves all those shortcomings and potential pitfalls. A few of them are:

cu, w0lf.

nylen commented 5 years ago

This has nothing to do with how many plugins use jQuery. All I'm saying is that the core JS scripts that are used for ClassicPress should simply be rewritten.

Well, it depends. We can rewrite the core JS scripts, but if we no longer enqueue jQuery by default then I suspect this will break more plugins and themes than you might expect. Hence the request to look into that.

Beyond that, I expect plugins will also be adding scripts that hook into or modify the core JavaScript in various ways. I don't know as much about what that might look like off-hand, but I would bet that more complicated plugins like (for example) ACF wouldn't work after the rewrite without some special attention.

We've inherited a very large ecosystem of plugins and themes, many of which continue working because the code behind them is largely unchanging rather than because they follow all the best practices. We owe it to our users to be extremely careful with any changes that might cause compatibility breaks, and this most certainly is one of those changes.

This isn't a new feature. It's an enhancement

The same principle applies - the petitions site is the best way we currently have to decide how we will prioritize high-level development tasks, based on the actual needs/wants of our user community. This particular task would be a huge time commitment, frankly with no guarantee of success due to the amount of code involved and the complexity of other code that depends on it. I think it's something that would help move the platform forward, but it is a good idea to gauge the interest of the rest of the community before jumping into it.

Mte90 commented 5 years ago

Also we have to consider that the media picker is built with backbone that use jquery, also lightbox use jquery too and a lot of plugins use it. In few words is an huge job that can create a lot of issues

C-Lodder commented 5 years ago

Petition created: https://petitions.classicpress.net/posts/187/jquery-to-vanilla-js

ClassyBot commented 3 years ago

This issue has been mentioned on ClassicPress Forums. There might be relevant details there:

https://forums.classicpress.net/t/jquery-to-vanilla-js/2905/2

viktorix commented 1 year ago

The petition was closed. Closing issue.