10 ms·
Sprint – A high-performance, DOM library for modern browsers
- tonypace 11y agoI am tired of terribly slow mobile sites. A demo of the difference would help.
- creshal 11y agoI ran the first benchmark linked in the readme on my mobile phone (2013 Moto G, i.e. old mid-end phone) and on my laptop (Thinkpad X230 i5-3320M), both on Firefox: Sprint (phone): 33.1 kops jquery (phone): 8.8 kops zepto (phone): 10.1 kops Sprint (laptop): 1435.2 kops jquery (laptop): 49.2 kops zepto (laptop): 65.9 kops Not bad, if that translates to real world performance.
- hackerboos 11y agoThis only supports IE10+. Why shouldn't I just use Javascript directly?
- Jgrubb 11y agoNot the author, but the API still sucks to write using vanilla JS. There are also still plenty of inconsistencies in modern browsers (per an article floating around here in the last day or two).
- smt88 11y ago> the API still sucks If you want syntactic sugar, a better alternative to a client-side library (which has overhead) is to use something like TypeScript (or one of the other compile-to-JavaScript options).
- anentropic 11y agothey solve different problems though... syntactic sugar from TypeScript et al solve problems with Javascript the language jQuery solve problems with the various builtin APIs like DOM etc that are part of either Javascript or the web browser host
- smt88 11y agoI just assumed the person I was replying to was complaining about document.getElementById('whatever') (etc.) vs $('#whatever'). In response to your comment, polyfills are more future-proof solutions to browser compatibility, which is the only remaining problem that I see jQuery as solving well.
- Jgrubb 11y ago> I just assumed the person I was replying to was complaining about document.getElementById('whatever') (etc.) vs $('#whatever') Actually that is what I was referring to. I must not have given TypeScript enough of a shake. I couldn't find the section in the early tutorial that showed me that sugar, and I also couldn't figure out how the typing stuff would help me working with a bunch of network-y type apps. Obviously this is my own failing. Inspired now to give it another shot, so thanks.
- smt88 11y agoIt's entirely my own fault, but this has been a really muddled conversation. When I mentioned TypeScript, I only meant that it (and other languages that compile to JavaScript, like Go) is a better syntax overall. I didn't actually mean that it helps with DOM selection/manipulation. So if you want short DOM syntax, I'd suggest using vanilla ES6[1] with polyfills, and then figure out what's really wasting your time. Then, you can write your own sugar for it. In my opinion, document.getElementById is something that you end up writing a lot and is really long, but with autocomplete in a good IDE, it's not a big deal. Plus, any JS developer who sees it will know exactly what it does and what it returns. 1. https://babeljs.io https://babeljs.io
- masklinn 11y agoThe DOM API remains complete garbage unless you're operating readonly on a single node (then it's merely bad).
- zodiakzz 11y agoDo you have any examples? In my opinion the DOM API only sucked pre-IE9 because of all the inconsistencies and incompatibilities. I have dropped jQuery completely except for when I need some of its plugins because I end up having to access the internal DOM objects too often and using $el.get(0) all over the place is ugly and a PITA.
- vbezhenar 11y ago$('.something').toggleClass('collapsed') .click(somethingClicked); This simple and readable statement will turn into a lot of lines with DOM API.
- deleted 11y ago[deleted]
- thedufer 11y ago> I would argue that the second half is a little unfair, since that style of coding is entirely influenced by jQuery. You usually don't actually need to trigger a real DOM event there, you just want to execute some callback as if the element was clicked. Maybe I'm missing something, but the second half is adding an event handler (`somethingClicked` is presumably a function). That seems like a _very_ common thing to do regardless of jQuery.
- deleted 11y ago[deleted]
- masklinn 11y ago> This does get a little uglier if the intent is that you have multiple '.something' elements, though. That part of the DOM API will always be pretty gross compared to jQuery, I think. Well yeah hence my remark. Working on a single node in a single modern browser, the snippet will turn into var node = document.querySelector('.something'); node.classList.toggle('collapsed') node.addEventListener('click', somethingClicked); but if you need multiple nodes, now you have to manually loop and beware your closures. And that's a best-case scenario, then you start traversing the DOM tree, adding elements, using events delegation and changing attributes and things go south fast.
- ShahoA 11y agoIt doesn´t seem to support the jQuery .ajax() method, I hope its added soon
- shawabawa3 11y agoAgreed, ajax is usually the reason I just think fuck it and add jQuery
- akx 11y agoOr you could just look at, say, http://microjs.com/#ajax http://microjs.com/#ajax to find a nicer microlibrary to do exactly what you need.
- untog 11y agoI wish microJS had fields for NPM/Bower compatibility. A lot of these micro libraries don't have it.
- robin_reala 11y agoYou can always build a custom jQuery with just the AJAX functionality: https://github.com/jquery/jquery/blob/master/README.md#modules https://github.com/jquery/jquery/blob/master/README.md#modul...
- ZeroGravitas 11y agoMaybe using a fetch polyfill is more future looking? https://github.com/github/fetch https://github.com/github/fetch
- igvadaimon 11y agoI didn't find any information on browser support.
- shawabawa3 11y agoIt says IE10+, so I would guess any vaguely recent chrome/firefox/safari as well
- timdaub 11y agoYeah, its great that there are libraries like this that try to do better than the status quo. But, with every new library there's always the question about support. And so since there is no involvement perceptible on its Github page (no PRs, no issues and 3months without a commit), I wouldn't want to use this in production.
- JustSomeNobody 11y agoThat's the problem with all these JS libraries and frameworks. They are being written just to be written; only a handful have been vetted in production.
- kmfrk 11y agoA tiny, lightning fast jQuery-like library for modern browsers. Respectfully, this entire description is an oxymoron. Every time someone mentions a jQuery-like microlibrary, they just mean a jQuery without wide browser(-quirk) support. Browser support is a big part of what makes jQuery jQuery, and without it, you definitely get a much smaller library, but it is also very un-jQuery-like. :) Now for some praise! It makes me really happy to see a comparison - benchmark! - with competitors, which is something everyone should be required to do, when they create software with 40,000 similar offerings. Looking at you, Markdown editors!
- dheera 11y agoIn a horrendously framgented mobile internet, one of the few blessings we do have is that the vast majority of mobile web browsers are WebKit variants so this kind of makes a lot of sense if, say, you're only targeting iOS and Android default browsers. I'm curious if it will take jQuery plugins though. Will try later.
- robin_reala 11y agoiOS and default Android. If you want to ignore Firefox and Opera then that’s your choice I guess.
- untog 11y agoIt would be better to say that mobile benefits from modern browsers, not just WebKit ones. I've gone without jQuery on a bunch of mobile only projects and run into zero issues.
- ams6110 11y agoGP did say "vast majority" If you want to devote dev time to specialize for the relative handful of folks who run Firefox on their mobile device, that's your call.
- creshal 11y agoThe default Android browser is no longer supported, and the embedded Chrome is blink-based and less and less webkit-ish. (And even the different Webkit ports can't be thrown into the same bag. Compare e.g. Safari on OSX, Safari on Windows, Midori on Windows and Midori on Linux. Two webkit browsers, crass rendering and behavioural differences between them and on each platform.)
- arnauddri 11y agoThe readme presents it as a production-ready jquery alternative but there isn't a single test written and it looks like there's no support at all
- emodendroket 11y agoSounds pretty Web-scale.
- camilo_u 11y agoHow this compares to zepto? As far as i know, this is basically the same promise zepto does "A kind-of-jquery but faster (and only modern boys)"
- hellweaver666 11y agoIf you read the actual page you will see there are comparisons between Zepto, Sprint and JQuery for a bunch of it's core functions.
- rwaldron 11y agoYes, performance comparisons, but those could've been measurements of no-op versions of functions by the same name.
- rwaldron 11y agoThere isn't a single test for this project. How can its claims of jQuery-alike-ness be supported? Tests, or it doesn't exist.
- LocalPCGuy 11y agoBetter yet, the author should just implement the jQuery test suite, and give a rundown of what passes and what fails.
- rwaldron 11y agoI absolutely agree with this. Several years ago I did the same exercise with Zepto, which definitively disproved its compatibility claim.
- vbezhenar 11y agoI like this approach. I generally tend not to use jQuery, because native DOM API is often good enough for my needs, but it's not fun to write and read code using that API. jQuery for me is shortcuts and wrappers for this code.
- SimeVidas 11y agoFinally I can run .css() over 700,000 times per second. Also, the 30 KB saved over the wire means a lot because the average page size is over 1 MB.
- apendleton 11y agoNot supporting the selector for .on() and .off() is a pretty serious limitation; catching bubbled events on child DOM elements is a super-common jQuery pattern, and makes event-handling over a DOM that's having stuff added to it much more pleasant to write. It's also pretty fundamental to some third-party libraries that run on top of jQuery, like Backbone (at least if you use its View event handling).
- leeoniya 11y agoagreed. lacking event delegation is a show-stopper.
- latch 11y agoI've used [the very badly named] minified.js in the past, and I was quite happy. Has optional support for IE6. http://minifiedjs.com http://minifiedjs.com
- tshadwell 11y agoOr, you know, use the Javascript DOM APIs? They're really not at all that bad. var d = document.createElement("div"); d.className = "new"; d.innerHTML = "<p>Hi Sprint</p>"; Skimming through the code I'm not sure the authors really grok Javascript anyway, which might explain why they need a (pretty thin) custom API for the standard APIs. toArray should be simply this: function toArray(o) { return Array.prototype.slice.call(o) } Instead it's: var toArray = function(obj) { var arr = [] var i = obj.length while (i--) { arr[i] = obj[i] } return arr } This is just silly: prepend: function() { insertHTML.call(this, "afterbegin", arguments) return this }, var insertHTML = function(position, args) { var argsLen = args.length var contents = args [...] var domMethods = { afterbegin: function(el) { this.insertBefore(el, this.firstChild) }, Perhaps this isn't so constructive and I should fork the library and annotate every method with its vanilla Javascript equivalent. I'm sure this post is non-constructive in some respects but I like Javascript, I just wish people would learn how to work with the language it instead of replacing the API wholesale.
- BinaryIdiot 11y agoThere is a lot of uses of innerHTML in this code which causes browser reflow; might get better performance creating all of the HTML components via document.createElement() and using document.createTextNode() for all text within a tag itself. But yeah cherry-picking may not be the most constructive thing however you do have good points. The DOM API is kinda funky (I wish it did some things like chaining) but it's very simple. Half the times I write a very thin wrapper around it JUST to provide some chaining.
- sanderjd 11y agoSee, that's why I end up using these libraries. If I found myself doing the three statements for creating a div in your parent's comment, I'd pull that out into a function that does it, then I'd start finding other things to pull out as well, then I'd think "surely somebody has made a library that has these things pulled out nicely", and I'd find one of these libraries. Since I know that would happen, I just start with a library from the beginning. But I suppose I'd love one that is thinner, like your "very thin wrapper", if anybody has pointers.
- jackmoore 11y agoI think this needs some text outlining it's differentiation from Zepto. Why would I use this instead of Zepto?
- curiously 11y agoHey guys found this neat little library http://vanilla-js.com/ http://vanilla-js.com/ I get 12+ million operation (a true master race class) vs advertised 800,000 and peasantry of jQuery's 300,000. Not sure if I want to sacrifice performance for aesthetically better looking (debatable ofc) syntax and bother investing time learning how to do something slower.
- malandrew 11y agovirtual-dom is all you need: https://github.com/Matt-Esch/virtual-dom https://github.com/Matt-Esch/virtual-dom There is a reason why both elm and mercury uses virtual-dom under the hood to generate and manipulate the DOM. Plus you can render server-side: https://github.com/nthtran/vdom-to-html https://github.com/nthtran/vdom-to-html If you still want to work with existing html like templates, there is this project: https://github.com/TimBeyer/html-to-vdom https://github.com/TimBeyer/html-to-vdom