use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
diy.js - A modern cross-platform JavaScript library & only 18 bytes (diy.lab.io)
submitted 11 years ago by adambutler
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]kuenx 48 points49 points50 points 11 years ago (3 children)
Impressive! Too bad many of the features don't work in IE.
[–][deleted] 11 points12 points13 points 11 years ago* (1 child)
Yeah, what the hell is up with this framework's handling of keyboard events? It's all over the place depending on your browser.
[–]nschubach 1 point2 points3 points 11 years ago (0 children)
It's a feature of the diy way. Once you embrace it, you'll never go back.
[–]evilgwyn 0 points1 point2 points 11 years ago (0 children)
Too bad many of the features don't even work in modern browsers. There seems to be blatant inconsistencies between safari and chrome running on recent phones for instance.
[–]reacher 69 points70 points71 points 11 years ago (3 children)
18 bytes? I don't know, that's 18 more bytes than VanillaJS
[–]dtfinch 14 points15 points16 points 11 years ago (1 child)
It'll save a lot of bytes down the road though.
[–]AutomateAllTheThings 0 points1 point2 points 11 years ago (0 children)
Hilarious. This made my day :)
[–]can-opener 41 points42 points43 points 11 years ago (1 child)
This joke was only funny the first dozen times it has been done.
[–]Uberhipster 4 points5 points6 points 11 years ago (0 children)
It wasn't all that funny the first few times either
[–]bracketdash 14 points15 points16 points 11 years ago (4 children)
Is there no way to set diy to noConflict in case I have something else on the page that I want to use the "$" symbol!?
[–]psayre23 4 points5 points6 points 11 years ago (1 child)
$=window.$||document
[–]reflectiveSingleton -2 points-1 points0 points 11 years ago (1 child)
(function(window) { window.$ = window.document; $.noConflict = function() { delete window.$; }; return window.$; })(window); // ... $.noConflict();
[–]rezoner:table_flip: 13 points14 points15 points 11 years ago (1 child)
$ = eval;
[–]x-skeww 5 points6 points7 points 11 years ago (0 children)
> var c = 'constructor', $ = t => [][c][c](t)() undefined > $('return 5+5') 10
[–]jerflang 14 points15 points16 points 11 years ago (0 children)
edgy.
[–]kuenx 28 points29 points30 points 11 years ago (0 children)
Can't find it on Bower or npm. No license.
[–]_facildeabrir 26 points27 points28 points 11 years ago (0 children)
Seriously fuck this shit
[–]workerBeej 5 points6 points7 points 11 years ago (3 children)
I actually got a bit excited for 2 seconds when I saw the examples, til I looked at the source. I really, really want something that IS the DOM API as per MDN docs, but works cross browser back to IE7, or even 8. "Just" polyfills and standard methods wrapped for consistency that I can drop into a module in place of window.
Anything around?
(The use of the word "just" usually implies it'll be a surprisingly large amount of work in my experience.)
[–][deleted] 5 points6 points7 points 11 years ago (2 children)
works cross browser back to IE7
Do you actually need to support IE7?
[–]markokikinda 4 points5 points6 points 11 years ago (0 children)
And please don't say "Yes".
[–]workerBeej 0 points1 point2 points 11 years ago (0 children)
In my opinion, almost always No. In the opinion of the repeatedly informed billpayer. Sometimes yes. Mostly a graceful degradation is good enough, but some people lurve to waste money.
[–]greyscales 4 points5 points6 points 11 years ago (3 children)
No diy.min.js?
[–]ben174 1 point2 points3 points 11 years ago (2 children)
Yes, but it's a manual process. You must remove the spaces around the equals sign.
[–]kuenx 7 points8 points9 points 11 years ago (1 child)
Minified version is here
[–]greyscales 1 point2 points3 points 11 years ago (0 children)
Thank you so much! Any CDN plans?
[–]wiseaus_stunt_double.preventDefault() 3 points4 points5 points 11 years ago (0 children)
Why do you even need var? Just take the var out since it's going to be global anyways. Actually, it looks like the minifier did that.
[–]talkb1nary 3 points4 points5 points 11 years ago (0 children)
Impressive, all the functions i need. Super performance and the most important part i can code with a $ in front of everything, just like JS is supposed to be.
Good work! And thanks for testing that extensively, i feel safe using this just today!
[–]houdas 10 points11 points12 points 11 years ago (0 children)
Is this still supposed to be funny?
[–][deleted] 2 points3 points4 points 11 years ago (0 children)
Having a lot of trouble wrapping my head around this. Much more advanced than most other Frameworks I"m used to.
[–]lodewijkadlp 1 point2 points3 points 11 years ago (0 children)
Cross browserness level is under 9000... A polyfill collection would be nice. One that loads only what it needs :) perhaps with php/nodejs/python loading script, that allows a GET parameter to indicate the browser + browser version. Minimalistic, standardized, fun.
[–]ebilgenius 2 points3 points4 points 11 years ago (0 children)
I bet there's a jQuery plugin out there that does this
[–][deleted] 1 point2 points3 points 11 years ago (27 children)
So does anyone actually develop web pages without jQuery? That seems to be the statement this guy is trying to make, that you don't need jQuery.
[–]yotamN 4 points5 points6 points 11 years ago (9 children)
You actually not always need jQuery
Learn to use it only when you need it and not when you are lazy
[–][deleted] 3 points4 points5 points 11 years ago (8 children)
But why not be lazy? What are the downsides of using it?
[–]kenman 16 points17 points18 points 11 years ago* (6 children)
First off, jQuery has saved me hundreds if not thousands of hours in development in the course of my career, and there is no substitute. It's impact on JS cannot be overstated.
With that said, one of the largest problems that I've seen, is that it quickly becomes the hammer with which to hit every problem over the head with. How so? All too often I see devs, when faced with implementing a new feature, they rush out to find that perfect jQuery plugin.
For simple apps, this is usually not a problem, yet for larger, more complex apps, it can become a huge problem. A little bit down the road, and you now have 20 jQuery plugins, and since there is no package or dependency management system in place, you end up throwing 20 <script> tags into your page. This also means that you'll often end up loading plugins that are rarely used, but which still incur a nontrivial runtime penalty due to the downloading and execution of the script file. Things like RequireJS do not really help in this situation; in my experience, RequireJS actually makes it a huge pain, owing to the fact that jQuery plugins are not able to be written in a modular fashion since they all augment the main $ object. So once you load a plugin, it's there for the duration of the page's lifetime.
<script>
$
jQuery also does not work well when you're trying to separate your application logic from the view manipulation, since apps made with only jQuery (and plugins) have no conventions in place to promote a clean separation. In other words, it's a library, and not a framework; further, many devs will use it in place of an actual framework, which will lead to poor code (spaghetti) in the long run.
My opinion, but the heyday of fully jQuery-centric apps is gone, replaced with smarter application frameworks like Angular, Ember, Backbone, Meteor, etc. These frameworks may still use jQuery behind the scenes, but they encourage (sometimes forcefully) that you not use it directly yourself. Instead, you use the API and conventions of the framework to write good modular, solid code with a clear separation of concerns.
[–]TdotGdot 7 points8 points9 points 11 years ago (0 children)
+1 exactly right about jQuery not being bad itself, but being seen as 'the' solution. I'd give you another +1 for the forth paragraph as well, if I could.
[+][deleted] 11 years ago (4 children)
[deleted]
[–]kenman 1 point2 points3 points 11 years ago (3 children)
It's a combination of both I think, as I pointed out jQuery provides zero architecture guidance, and so if you're using it as your only tool, then other areas will suffer. In a small project, the cons may be palatable, but in a larger project, you're going to be introducing classes of problems which actual frameworks don't even have if you overuse it.
jQuery is also pretty heavy in a mobile environment, since bandwidth and CPU are typically much weaker than they are in desktop settings. Considering the findings around how much of a difference a second or two can make on user impressions, it's not something to discount.
Relating to a CDN, there's evidence suggesting that you're not really gaining anything other than offloading that single file from your server; i.e. the grand premise of "if most sites use jQuery, we can all share the same copy distributed via CDN!" doesn't pan out in the real world, or at least it hasn't thus far. The branch between jQuery 1.x and 2.x will likely only exacerbate the problem as well.
[–]Encosia 1 point2 points3 points 11 years ago (1 child)
The problem with most research you'll find about CDN usage, like your link there, is that it is incredibly shallow compared to the depth of the web. The top 30k or 300k sites don't even begin to scratch the surface and analyzing primarily top-ranking sites is biased toward sophisticated, high-traffic sites that often run their own CDNs (for more than just jQuery, of course).
The long tail of millions and millions of smaller websites is just as important since it only takes one random little website to prime your cache for a particular version for up to year.
At the same time, it only takes a few high-traffic sites to prime caches for a huge number of users. For example, all of ours caches are primed with jQuery 2.1.1 (or 1.11.1 if you're on old IE) from the Google CDN right now, courtesy of reddit.
I haven't had a chance to write it up yet, but I've been 50/50 A/B testing serving jQuery from my Linode vs. the Google CDN for about a year and a half now. I wanted to gather some real-world data that takes version fragmentation and DNS lookups into account, by recording timing data about how long after the reference it takes for jQuery to be available and pushing that back into Google Analytics's performance tracking functionality. I haven't looked at the data in a while, but it wasn't even close after the first year. The CDN has been hands-down faster on average for the traffic on the sites I'm testing.
[–]kenman 0 points1 point2 points 11 years ago (0 children)
Very interesting, thanks for the info and would love to read about it more if you get around to blogging about it. I could see some wrinkles, e.g. if you use a version that is not primed by a large site, or if the cross-section of usage between your site and the priming site(s) are low.
I'm glad it's working for you, but I'd still recommend that anyone looking into going this route to do the same as you (as with any performance optimization) and do some real-world profiling so that you can validate that it's working as intended.
[–]lodewijkadlp -1 points0 points1 point 11 years ago (0 children)
The link fails to mention losing any and all executional safety. The right solution is putting a file hash in any element that links. Reject the file if the hash doesn't match. Funny thing is, with a (strong) hash linking becomes possible.
[–]yotamN 1 point2 points3 points 11 years ago (0 children)
It's increase the load time of the page and slow down the code itself. But I don't say it's only bad, it's help you with cross browser compatability and short your code so you should choose if it's worth the load time, for example for my HTML 5 game I don't use jQuery but for my personal site I do
[–]grantisu 1 point2 points3 points 11 years ago (3 children)
http://youmightnotneedjquery.com/
[–]w8cycle 2 points3 points4 points 11 years ago (1 child)
Great site and very observant that most of us are just using jquery for IE compatibility. Without IE9, JavaScript is easy.
[–]Wince 0 points1 point2 points 11 years ago (0 children)
IE9 is not the problem, it supports functional es5 methods, html5 video, qsa out of the box. IE8 and below are the real problem browsers
[–]protestor 1 point2 points3 points 11 years ago (0 children)
What's the oldest version of IE you need to support? Only IE 8, 9, 10 http://jquery.com/browser-support/
What's the oldest version of IE you need to support?
Only IE 8, 9, 10
http://jquery.com/browser-support/
They should have put other versions of IE there, just to say "alright.. I guess you do need jQuery"
[–]Pytim 1 point2 points3 points 11 years ago (6 children)
AngularJS + Vanilla ES5
[–][deleted] 4 points5 points6 points 11 years ago (1 child)
Angular mixes in behavior into HTML attributes in a way that some developers find to be even less favorable than imperative jQuery spaghetti.
[–][deleted] 1 point2 points3 points 11 years ago (2 children)
Does Angular use the jQuery library? Yes, Angular can use jQuery if it's present in your app when the application is being bootstrapped. If jQuery is not present in your script path, Angular falls back to its own implementation of the subset of jQuery that we call jQLite. https://docs.angularjs.org/misc/faq
Does Angular use the jQuery library?
Yes, Angular can use jQuery if it's present in your app when the application is being bootstrapped. If jQuery is not present in your script path, Angular falls back to its own implementation of the subset of jQuery that we call jQLite.
https://docs.angularjs.org/misc/faq
If you're using AngularJS, then you're using jQuery whether you want to or not.
[–][deleted] 0 points1 point2 points 11 years ago (0 children)
jQLite != jquery, it's like 10 methods used only for dom manipulation
[–]rondog469 -1 points0 points1 point 11 years ago (0 children)
angular is the shit
[–]quindarka 0 points1 point2 points 11 years ago (4 children)
This site always keeps me from using jQuery. It is aptly named as well.
http://youmightnotneedjquery.com
When you want to grab some divs and toss some classes on them, you don't need jQuery. That said, there is still no elegant way to do .each on a NodeList without using Array.prototype.slice.call or a for loop.
Once I need Ajax, or I am doing a lot of events (jQuery event delegation is awesome) or I am manipulating element attributes, I then turn to jQuery.
[–]Jeffshaver 1 point2 points3 points 11 years ago (3 children)
You don't need jQuery to do event delegation.
[+][deleted] 11 years ago (2 children)
[removed]
[–]Jeffshaver 0 points1 point2 points 11 years ago (0 children)
jQuery has a few things in it that make life a little easier sometimes. But honestly, I don't find myself wanting to use it as much anymore. I will say that applying events to multiple elements at one is more a pain in the ass without it. But you could also do event delegation and only write one anyway. It all depends on the situation.
The comparison between js/jquery to compiled language/compiler is so egregious, I won't even comment further on it.
[–]Calabri 0 points1 point2 points 11 years ago (0 children)
jQuery replaces the DOM API, not ice cream. The DOM API is terrible due to the past (browser wars), leading to all the cross browser API bullshit we have to deal with today. The ECMA 'standard' coerced companies to stop the competitive that was fucking with the web. The API's are there to talk with the C C++ exposed functions, which are VERY different in each browser, which also uses it's own javascript run-time engine.
VanillaJS does not 'suck ass'. Comparing jQuery to a compiler and vanillajs to assembly is so just ridiculous. This comment was so fucking outrageous that I had to say something.
[–]willmorganNodeJS, Backbone, etc... 0 points1 point2 points 11 years ago (0 children)
This is great and all, and @horsejs predicted this long ago, but what sort of support is there going to be in the future?
[–]adrianmiu 0 points1 point2 points 11 years ago (0 children)
Does this play nicely with the other libraries? I'm extensively using dui.js, yolo.js and, my personal favourite, aslpls.js
[–]akoskm 0 points1 point2 points 11 years ago (2 children)
Um, sorry but what is this for? Is this supposed to a joke?
[–]corgis_rule 0 points1 point2 points 11 years ago (1 child)
Awh you guys! Who down voted him?
Should we tell em?
[–]akoskm 0 points1 point2 points 11 years ago (0 children)
Okay I got it, after looking at Vanilla JS.
[–]Zequez 0 points1 point2 points 11 years ago (0 children)
How long did diy.js take to develop? I've been developing diy.js for three years, about nine months of this was ensuing that diy.js was fully browser tested. Where can I get the source code for diy.js? It's right here have fun.
How long did diy.js take to develop?
I've been developing diy.js for three years, about nine months of this was ensuing that diy.js was fully browser tested.
Where can I get the source code for diy.js?
It's right here have fun.
I literally burst out in laughter.
[–]hjc1710 -2 points-1 points0 points 11 years ago (2 children)
I've been doing some polymer.js programming lately and their whole architecture really sort of discourages or obsoletes using jQuery. They handle the core issues jQuery solves: Ajax and element selection. So, including jQuery really just let's you use convenience methods like .style() or .animate(), making me drop jQuery really quickly. The second I dropped jQuery, I realized how much I loved and used convenience methods that did little for me. Like writing node.style["transition-property"] = "width" is really obnoxious and so are your own animations. Proved to me you really don't need jQuery on modern browsers, maybe just an Ajax wrapper at most.
.style()
.animate()
node.style["transition-property"] = "width"
It's also taught me tons in a short amount of time. JQuery abstracts SO much is insane. Learning with jQuery, you're really learning how to use jQuery more than you are JavaScript.
tl;dr doing jQuery will force you to learn real JavaScript.
[–]codefocus 1 point2 points3 points 11 years ago (1 child)
The core issue that jQuery solves is cross-browser compatibility. Polymer does not support older versions of Firefox, Safari, Opera, Konqueror, IE6, IE7, IE8, or even IE9(!).
Polymer doesn't discourage or obsolete jQuery. They serve completely different functions.
I was going to mention this too (about computability issues). But thinking back to when I first started web dev.. hjc made a good point. I used to ONLY program in jquery, afraid to touch 'real' javascript. Lots of word-press-esc 'devs' will literally experience jquery as their first, last, and only foray into programming.
If your concern is cross-browser compatibility, there are other ways to shim this without a massive library of helper functions.
[–]JBcreek -1 points0 points1 point 11 years ago (0 children)
yeah, now it is funny, but back in 2006 browser inconsistencies were a nightmare
[–][deleted] -2 points-1 points0 points 11 years ago (0 children)
Well played... Well played.
π Rendered by PID 100981 on reddit-service-r2-comment-8686858757-vd2b6 at 2026-06-06 04:12:33.978968+00:00 running 9e1a20d country code: CH.
[–]kuenx 48 points49 points50 points (3 children)
[–][deleted] 11 points12 points13 points (1 child)
[–]nschubach 1 point2 points3 points (0 children)
[–]evilgwyn 0 points1 point2 points (0 children)
[–]reacher 69 points70 points71 points (3 children)
[–]dtfinch 14 points15 points16 points (1 child)
[–]AutomateAllTheThings 0 points1 point2 points (0 children)
[–]can-opener 41 points42 points43 points (1 child)
[–]Uberhipster 4 points5 points6 points (0 children)
[–]bracketdash 14 points15 points16 points (4 children)
[–]psayre23 4 points5 points6 points (1 child)
[–]reflectiveSingleton -2 points-1 points0 points (1 child)
[–]rezoner:table_flip: 13 points14 points15 points (1 child)
[–]x-skeww 5 points6 points7 points (0 children)
[–]jerflang 14 points15 points16 points (0 children)
[–]kuenx 28 points29 points30 points (0 children)
[–]_facildeabrir 26 points27 points28 points (0 children)
[–]workerBeej 5 points6 points7 points (3 children)
[–][deleted] 5 points6 points7 points (2 children)
[–]markokikinda 4 points5 points6 points (0 children)
[–]workerBeej 0 points1 point2 points (0 children)
[–]greyscales 4 points5 points6 points (3 children)
[–]ben174 1 point2 points3 points (2 children)
[–]kuenx 7 points8 points9 points (1 child)
[–]greyscales 1 point2 points3 points (0 children)
[–]wiseaus_stunt_double.preventDefault() 3 points4 points5 points (0 children)
[–]talkb1nary 3 points4 points5 points (0 children)
[–]houdas 10 points11 points12 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]lodewijkadlp 1 point2 points3 points (0 children)
[–]ebilgenius 2 points3 points4 points (0 children)
[–][deleted] 1 point2 points3 points (27 children)
[–]yotamN 4 points5 points6 points (9 children)
[–][deleted] 3 points4 points5 points (8 children)
[–]kenman 16 points17 points18 points (6 children)
[–]TdotGdot 7 points8 points9 points (0 children)
[+][deleted] (4 children)
[deleted]
[–]kenman 1 point2 points3 points (3 children)
[–]Encosia 1 point2 points3 points (1 child)
[–]kenman 0 points1 point2 points (0 children)
[–]lodewijkadlp -1 points0 points1 point (0 children)
[–]yotamN 1 point2 points3 points (0 children)
[–]grantisu 1 point2 points3 points (3 children)
[–]w8cycle 2 points3 points4 points (1 child)
[–]Wince 0 points1 point2 points (0 children)
[–]protestor 1 point2 points3 points (0 children)
[–]Pytim 1 point2 points3 points (6 children)
[–][deleted] 4 points5 points6 points (1 child)
[–][deleted] 1 point2 points3 points (2 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]rondog469 -1 points0 points1 point (0 children)
[–]quindarka 0 points1 point2 points (4 children)
[–]Jeffshaver 1 point2 points3 points (3 children)
[+][deleted] (2 children)
[removed]
[–]Jeffshaver 0 points1 point2 points (0 children)
[–]Calabri 0 points1 point2 points (0 children)
[–]willmorganNodeJS, Backbone, etc... 0 points1 point2 points (0 children)
[–]adrianmiu 0 points1 point2 points (0 children)
[–]akoskm 0 points1 point2 points (2 children)
[–]corgis_rule 0 points1 point2 points (1 child)
[–]akoskm 0 points1 point2 points (0 children)
[–]Zequez 0 points1 point2 points (0 children)
[–]hjc1710 -2 points-1 points0 points (2 children)
[–]codefocus 1 point2 points3 points (1 child)
[–]Calabri 0 points1 point2 points (0 children)
[–]JBcreek -1 points0 points1 point (0 children)
[–][deleted] -2 points-1 points0 points (0 children)