rivets
rivets copied to clipboard
Prevent use of jquery?
I am currently working on an application which has some legacy jquery but which will eventually get removed.
rivets is using that jquery installation, but I'd rather prefer that it would not. Is there a way to prevent rivets from using jquery?
Well, for now rivets will use jquery if it exists. The existence of jquery is tested when Rivets is executed so you may play with script order in your HTML in order to have Rivets before jQuery. If you cannot change order, just add this code (not pretty but should do the trick)
<script>
window._jQuery_ = window.jQuery;
window._$_ = window.$;
delete window.jQuery;
delete window.$;
</script>
<script src="your/path/to/rivets.min.js"></script>
<script>
window.jQuery = window._jQuery_;
window.$ = window._$_;
delete window._jQuery_;
delete window._$_;
</script>
It should help you until we decide what to do in next version
Thank you very much! That's a workable solution.
I am wondering, why you don't drop the use of jquery anyway. Since rivets works with plain JS, doesn't the jquery specific code just bloat the code base?
BTW, if you want, you can close this "issue".
I must admit I don't have an opinion on the use of jQuery. I don't know why it was done so. @Duder-onomy @Leeds-eBooks do you think we must/can remove use of jQuery?
I imagine this was done originally so that rivets could support older browsers without having to bring its own polyfills. If we remove jQuery usage, I think we will lose support of some old browsers? I personally think we have a duty to make those browsers obsolete by not supporting them but this is a personal and somewhat controversial opinion and not something that should be enforced by an open source lib, probably. A better solution might be to pass jQuery into rivets.configure()
, perhaps? This allows the dev to have the final decision.
My 2 cents:
jQuery is present throughout the code base: utils binders views
If we were to make a flag to toggle the use of jQuery on and off, then we would need to put a if check in all of those locations.
It should probably be removed eventually, and the actual uses of jquery in rivets are pretty well supported dom api's at this point. In rivets, jquery is used to do 'addEventListener', 'removeEventListener', get values from anything using the rv-value
binding, and iterating an array of dom nodes. These are all pretty trivial tasks in 2016.
My gut says it could be extracted with little fallout. Especially since we are trying to follow semvar, people can also get the old versions if they need it.
If the rationale behind the support of jquery was based on browser support for [add|remove]EventListener, then it comes down to browser statistics. And then the remaining question is the one of more or less arbitrarily deciding whether the percentage of browsers which require that kind of pampering falls below a certain threshold.
The overall use of ie8 has dropped below 0.1%. But that's only considering the Desktop.
Maybe removing jquery code is a candidate for the es6 version?
http://caniuse.com/#search=addEventListener I think support is good enough. JQuery now only supports IE9+ and addEventListener works in IE9 so there really is no need to use JQuery
The general consensus appears to be that we remove it. I think I will make a start on a PR for it.