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

Warn about jQuery usage on the front end #402

Open
adamsilverstein opened this issue Oct 6, 2021 · 6 comments
Open

Warn about jQuery usage on the front end #402

adamsilverstein opened this issue Oct 6, 2021 · 6 comments

Comments

@adamsilverstein
Copy link
Member

While it has been widely known that you might not need jQuery for most of your interactive theme features, jQuery is still a common JavaScript dependency found in WordPress themes - for example, 7 out of the 11 default themes since Twenty Ten use jQuery in the frontend.

A recent analysis of the performance impact of using jQuery in WordPress themes determined that jQuery is the most common JavaScript-based performance problem in themes and that Removing jQuery may lead to 80% less JavaScript load. According to the analysis, most themes can easily substitute (modern) vanilla JavaScript and remove their reliance on jQuery with only minor changes.

To help theme developers make better choices in the future, I would like to add a warning to the theme-check plugin when themes enqueue 'jquery' on the front end (eg. wp_enqueue_script). The warning could reference the analysis and perhaps offer a link to an article explaining how to switch to vanilla JavaScript.

If this idea seems reasonable, I am happy to work on a PR to add this.

@pattonwebz
Copy link
Member

pattonwebz commented Oct 6, 2021

This idea seems reasonable (maybe even the responsible thing to do) to me, bonus points if the warning message is friendly and inviting instead of scary :)

@carolinan
Copy link
Collaborator

Yes, I had it on my to do list but if you want to work on it that would be great.

There is also the scenario where the user tries to include and enqueue their own version of jQuery -that should block theme upload.

@adamsilverstein
Copy link
Member Author

There is also the scenario where the user tries to include and enqueue their own version of jQuery -that should block theme upload.

Good point @carolinan - so would we detect the actual inclusion of jquery with the theme, or the enqueueing, or both? I guess some themes might try to enqueue from a CDN, or is that already covered by a different check?

I'm going to open a separate issue for this ^^ so I can keep my work here focused on the narrow case of warning about enqueueing jquery on the front end.

@carolinan
Copy link
Collaborator

carolinan commented Oct 13, 2021

Both.
There is a CDN check but it is limited to a list of well known CDN's.
https://github.com/WordPress/theme-check/blob/master/checks/class-cdn-check.php#L44

@adamsilverstein
Copy link
Member Author

adamsilverstein commented May 6, 2022

@carolinan finally found time to get back to this and opened #423 to address.

I tested this locally to verify it works :) Still have some questions about the implementation which I will leave as comments on the PR code

Also, welcome any suggestions to improve wording/language to make it more "friendly and inviting instead of scary :)"

@adamsilverstein
Copy link
Member Author

@carolinan this is ready for review whenever you have a chance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants