-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[ FEEDBACK WANTED ] Velocity is dropping jQuery #205
Comments
How will this affect the amount of work that goes into Velocity? It seems like it might end up as a sort of split codebase, but I haven't looked at the source at all, so I don't know how much it relies on jQuery right now. I personally don't think I'll use it, but I'm glad that it's an option if I need it. |
Hey @WesleyAC, Great question. The reason I waited this long to release the shim is to ensure that the shim file will never have to be touched. If Velocity winds up needing more jQuery functions in the future (which is highly unlikely), I will simply bake them into Velocity directly. As for how this affects Velocity itself: It won't. I actually don't have to go out of my way to add compatibility for the shim (as opposed to jQuery proper); the architecture of Velocity is such that Velocity can automatically attach itself to jQuery, Zepto, or the plain In short, this won't affect development load on Velocity at all :) |
Dumb question: Why? Which use cases are improved with the shim and how? |
@ianmaddox: Not a dumb question at all. Example use cases:
Tangent: Some people also steadfastly refuse to use helper libraries like jQuery/Zepto for "performance reasons." These people are idiots. They're forsaking extreme efficiency and cross-browser normalization because they think they're saving on precious Kb and ms. Truth is, you can remove one image from your page to make up for the Kb jQuery takes up, and the performance degradation you experience with jQuery (on the scale of a few milliseconds) is completely negligible in the real world for everything but animation, which Velocity already solves. |
👍 I think this is great. I'm already using React, superagent, LoDash, bluebird, and other specific-purpose libraries, so I find myself not needing the DOM, Ajax, or general utility functions built into jQuery. The performance has never been an issue, but the API for Ajax, the broken promises/deferreds, and the overall large surface of jQuery is a drag, especially if you don't have to target less modern browsers. I think the loss of I definitely like the plain Is there a WIP of the shim or anything like that? I'm not very familiar with the internals of Velocity, so it would be cool to read through the source to see what's being shimmed specifically. Edit: I did some digging. Is this about the whole of it here? |
Thanks for contributing this. Another great example of when people don't need jQuery.
Couldn't agree more.
True. Definitely a point against going with that option. As it is, I'm already leaning toward having the two versions. If people wouldn't complain about the 4Kb file size boost, my genuine preference would be to just have a singular
Yeah, but I need to clean it up. I can post a link on here in a couple days :) |
This system works for me because we have no short term plans to move off of Zepto. Having the shim included as part of the main file makes my life a little easier. That said, I think if I were using jQuery I'd prefer that 4kb be left out of what I'm loading. Right now, we use require to concatenate scripts together so it doesn't really cost us anything to have the shim as separate file. Whatever works best for you here and is easiest to maintain is the right answer. I wouldn't stop using Velocity because it was 34kb minified vs 30kb minified so that shouldn't be your decision maker. Another potential reason to have two versions or just have the shim is that 90% of your use case is probably going to be jQuery users. Those who aren't using jQuery should be able to read enough to find the shim or alternate file. Those who are can just use the file as is. 😎 |
Personally I like your third choice with 4 files in total (doubled due to minified versions) -
The loss of jQuery functions isn't really an issue - if someone doesn't want to use jQuery then they've not got access to them to start with, and the more people using velocity the more feedback and ideas come in and the better it gets :-) Most people who don't bother reading things are likely to just use the main named file without the "jquery" part in it - which would be the "works everywhere" one - though the temptation there is to rename the whole project to something to discourage inane and already-answered questions (iq-test.js maybe? :-P) You could potentially have lazy-loading of the shim if jQuery isn't loaded - but I'm not a fan of scripts adding extra scripts, not least because of the whole issue about where to load it from etc. |
For now on, I always try to avoid jQuery. In some cases, it's usefull, for others, it's not. But I'm not here to talk of it. IMO, maybe you should provide your script twice, (velocity.js + jquery.velocity.js) because some devs will ever use jQuery, or sometimes, they have to. For the shim, if it's really light, why not including it in velocity core's ? 4kb minified is not a shame, and I think it could be easier to use for newbies. You could then share only 2 core files, velocity.js & jquery.velocity.js. Thanks :-) |
Regarding your questions:
Dropping the jQuery dependency is a really good move, thanks for taking the extra effort to make it happen. |
As a massive jQuery user, I won't mind if Velocity have a single file I think that someone who uses jQuery shouldn't care about add 4kb to its page (if he does, he should just stop to use jQuery which weight 94kb already). Thanks for developing and maintaining Velocity. |
I'm all for it, There is no benefit to splitting out the code? I'd imagine the ability to drop support for IE8 would benefit in some way no? I'm all for dropping IE8 by the way, all major frameworks are starting to do so and I'd say it's about damn time. I'd have thought it would be lower than 10% by now but some people / companies just can't seem to let go... Even so, for IE8 I will not shed a tear, and I try to educate our bussinesses to do the same. |
Good point, @Rycochet. Thanks for the feedback, @thiphariel!
@lmartins & @Oliboy50: This is what I'm hoping most people will say as well. Would love to get a poll going.. @kevin-smets There is no perf benefit to dropping IE8, and there would only be maybe 25 lines dropped in terms of file size. So, no real impact. But, darn, am I happy to see IE8 dying.... Thanks, guys! Keep 'er comin'! |
My initial reaction to this was somewhere along the lines of "please make at least one release completely without the shim so I won't have to load unnecessary bytes", but the more I think about it the less it matters really. I think having just one release with velocity and the shim combined would be totally fine. If you're afraid people will not be using Velocity it because of the "unnecessary" 4 kB, you can simply market it like this: "Velocity works without jQuery, but attaches itself to it if it is available". You don't really need to mention that it includes a jQuery shim. This way it is more a bonus, really. Also keep in mind that most people gzip their content as well (at least I hope so), which makes the 4 kB even less significant. Might I add that dropping the jQuery dependency is a really awesome move. I wish more libraries would go in this direction. |
Thanks so much for that, @bendiksolheim. That's what I secretly wanted someone to say :) Definitely reassuring. I would LOVE, LOVE, LOVE to just have a singular velocity.js version. |
Going to weigh in on this and throw my weight (all 165lbs of it!) behind the one codebase option. It's infinitely easier to have a one file to rule them all solution. We all know what a pain it is to maintain appendages of code. Having a jQuery shim makes definite sense, as lots of people use jQuery, and are very familiar with a specific convention of API. So to summarize, removing the direct dependency to jQuery is definitely the preferred option, with the added shim to adapt it to work with a familiar API. |
If possible, one codebase. There's no way you can be against that :). |
I like how the "Velocity works without jQuery, but attaches itself to it if it is available" statement from @bendiksolheim sums up this approach. It could also transition to highlight some of the benefits of using Velocity directly for certain things, like returning promises, and especially the internal-but-exposed Velocity.CSS implementation, which is fantastic if you're not doing imperative DOM structure manipulation (i.e., doing it declaratively with React or Angular). Also, I just wanted to say your desire for and response to feedback evidenced here is awesome, and I think it reflects in the tone of the discourse. It's really exemplary of how welcoming and productive open source development can be when done right. |
@jordansexton Thank you so much for the kind words. In a minor twist / change of heart, I'm now leaning toward just going with |
You mean you're going to two files after all? |
At least to start. This way, at minimum, we can iron out if there are any bugs and I can reconsider a merger (thanks to the comments in this thread) down the line. |
Any chance of wrapping it in a UMD? |
Haha now I'm confused.
|
|
I think the UMD thing should be a totally separate issue - for when you reach v1 or later - split velocity up into separate parts that can then be put together by a build script or similar to let people build their own custom versions skipping things they don't want/need so they can strip every possible byte from things ;-) Until then I want to say "stay on target, stay on target", but don't like the obligatory red-shirt moment that comes afterwards :-P |
+1 for Zepto support; in my opinion that's more important than the no-dependency route. You could handle this as a separate issue to allow for more focused discussions as this conversation revolves around the shim thing (which I find a good idea of handling this approach in beta state). |
Is there a way to test this out now? I am using velocity with npm / browserify and can't figure out how to keep from getting the global $ error thrown, other than including jquery in a script tag ( eww ). Ideally I would be able to:
|
Google for how to require a jquery plugin. There's a shimming process. (No relation to my shim.) Sent from my phone
|
What he said ^ We've defined our shim like so:
This works for us. |
Is the non-jquery already available for testing? |
Thanks, found this helpful stackoverflow for those interested: @scalvert The shim you supplied here is from a grunt task? @julianshapiro Should this be added to the docs? Will this remove the hard dependency on the global $ variable? Would be awesome to not have to shim anything and just pass an element to Velocity.animate as I think you mentioned before. |
Hey Luis. No, there appears to be a bug on iOS6. Looking into it this week. Sent from my phone
|
Fixing an obscure iOS6 bug in the next ~14 days then this will finally be released. Will open a new thread then. Thanks, everyone. |
If anyone's curious what's taking so long, read this: #208 I could use your help! |
Big news. Spread the word. Velocity has DROPPED JQUERY! See http://VelocityJS.org/#dependencies . |
This is great news!! |
@nmussy developed a shim for the jQuery functions that Velocity depends on. I'm now focusing my attention on releasing this work. (I waited until all core Velocity features landed, which they now have.)
The shim works as follows:
jquery.velocity.js
. Velocity automatically detects the shim then uses it for some of its internal functions -- so long as jQuery isn't also present on the page, in which case Velocity will always default to using jQuery proper.jquery.velocity.js
works exactly as it does now. No changes are being made to the core Velocity file. The shim's purpose is to simply act as a polyfill.$("div").velocity()
won't work since you don't have access to jQuery's selector engine nor its chaining capabilities. Accordingly, all shimmed Velocity animation takes place via Velocity's utility function: http://velocityjs.org/#utilityFunction. Note that, when jQuery is loaded on the page, the utility function is normally an extension of jQuery's$
object. However, when jQuery isn't loaded (meaning, the shim is being used), the utility function is attached directly onto thewindow
object and is therefore accessed simply viaVelocity.animate(element, propertiesMap, options);
This is the new syntax for animating with the jQuery-free version of Velocity.$
and$.fn
and will automatically work exactly like it already does with jQuery, e.g.$zeptoElement.velocity();
. Without the shim,jquery.velocity.js
currently does not work at all with Zepto.Questions for you guys:
velocity.jquery-shim.js
,velocity.shim.js
, or something else?jquery.velocity.js
be renamed to simplyvelocity.js
? Note that the shim has a minified size of 4Kb and that minified Velocity is currently at 30Kb.velocity.js
andjquery.velocity.js
. One of them simply bakes in the shim code at the top. Accordingly, the shim itself would not be released as a separate file. (My concern with this option is that there starts to be a lot of download options for users, and I don't want to make them think twice about what file to use.)Notes:
jquery.velocity.js
, will not be supported in the shimmed version.delay()
andqueue()
functions when not using jQuery, you'll want to replicate their behavior by leveraging Velocity'sdelay
option as well as itsbegin
/complete
callbacks.Any questions, concerns, or comments?
The text was updated successfully, but these errors were encountered: