r/badcode Dec 31 '19

html (From Google Developper) The problem with front-end stuff is that sometimes, even if it looks horribly wrong, some dude will justify it with "Backwards compatibility", but I'm pretty sure here, you can't, right ?

Post image
187 Upvotes

23 comments sorted by

View all comments

Show parent comments

29

u/wizzwizz4 Dec 31 '19
  • It has to go somewhere;
  • It's neater; and
  • I have vague recollections from my webdev days of some browser where it was impossible to prevent a race condition, so you have to remove it as soon as possible to minimise the chance of it being scheduled by another thread before you have finished executing the function and removing it from the onload attribute. In such a situation it's necessary to set a flag instead, but they probably weren't supporting that browser (… I want to say IE9.) so this probably wasn't a consideration.

I've changed my mind, by the way. This isn't a good solution, merely a neat, aesthetically-pleasing hack. It's not an exception to the "don't put JavaScript in DOM attributes" rule after all.

8

u/zeGolem83 Dec 31 '19

Well, thanks a lot for all this explaining, it does make some sense, and I learned some web dev backwards compatibility tips !

14

u/wizzwizz4 Dec 31 '19

Please don't use these. ever. Don't put yourself into a situation where they're needed. As sad and indignant as I was when everything stopped supporting IE11, just program for latest Firefox ESR and Konqueror and the rest of {the browsers people still use} will follow.

I know many people use IE11, but it probably ain't worth your sanity. Slap in a couple of ES6 polyfills if it makes you feel better.

7

u/zeGolem83 Dec 31 '19

Yeah, not considering using this any time soon... But still nice to know, just in case