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 jquery rails #4034

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

Conversation

josemigallas
Copy link
Contributor

@josemigallas josemigallas commented Mar 5, 2025

TL;DR

UPDATE: It was not so simple!

Description

Forms and other asynchronous stuff is managed by rails-ujs (Unobtrusive scripting adapter for jQuery).

It is embedded in the jQuery imported as gem jquery-rails as following:

//= require jquery
//= require jquery_ujs

In recent rails (5+), rails-ujs is included in the gem rails and it's imported like this:

//= require jquery
//= require rails-ujs

Moreover rails-jquery includes jquery 1, 2 and 3:

//= require jquery
//= require jquery2
//= require jquery3

Therefore, the best way to unify jquery 1 is to remove all other from assets/vendor and just use the one provided by this gem.
Webpack packages will still use jQuery 3.x from node_modules and there's even a node module for rails-ujs... so in time we'll see wether we stick to Gem of NPM.

@josemigallas josemigallas self-assigned this Mar 5, 2025
@josemigallas josemigallas force-pushed the clean_up_jquery_rails branch from 09ff0fd to cbe979d Compare March 5, 2025 10:44
Copy link
Contributor

@jlledom jlledom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't compile assets:

Sprockets::FileNotFound: couldn't find file 'vendor/jquery-1.11.3.min.js' with type 'application/javascript'

@josemigallas josemigallas force-pushed the clean_up_jquery_rails branch from cbe979d to a2dc400 Compare March 6, 2025 07:46
@@ -238,7 +238,7 @@ def self.replace_googleapis(url)
return url unless Rails.env.test?

if url =~ %r{//ajax.googleapis.com/ajax/libs/jquery/(.+?)/jquery.min.js}
"vendor/jquery-#{$1}.min.js"
"essential_assets/jquery-#{$1}.min.js"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OMG, why did we have googleapis in the first place??!

Looks like there is still some leftover:

<script src="//ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js" type="text/javascript"></script>

I think in the next PR we'd need to remove both this helper, and that external JS.

@josemigallas josemigallas marked this pull request as draft March 13, 2025 08:42
Copy link
Contributor

@jlledom jlledom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works apparently fine for me 👍

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

Successfully merging this pull request may close these issues.

3 participants