Leveling up your JavaScipt - DrupalJam 2017

Christian Heilmann
Christian HeilmannSenior Program Manager Developer Experience and Evangelism at Microsoft
Chris Heilmann @codepo8, DrupalJam, May 2017
Of innovation and impatience
Chris Heilmann @codepo8, Future Decoded, London, Nov 2015
CHRIS HEILMANN
@CODEPO8
codepo8.github.io/logo-o-matic
codepo8.github.io/canvas-images-and-pixels
Pixels are my thing… :)
We all know this
character, right?
https://en.wikipedia.org/wiki/Mario#Concept_and_creation
But do you know
why it looks like it
does?
https://en.wikipedia.org/wiki/Mario#Concept_and_creation
Red and Blue offered the
best contrast to the skin,
boots and the game
background.
https://en.wikipedia.org/wiki/Mario#Concept_and_creation
The cap meant there was
no need to worry about
hair style, eyebrows and
forehead.
(There were also not enough
pixels for waving hair when
falling down a hole)
The large nose and
moustache made it
possible to avoid a mouth
and facial expressions.
Design by limitations.
!
Design by lack of definition.
🌎🕸
Flexibility and forgiveness…
💧 HTML and CSS are fault tolerant…
Knives, bees and footguns…
🦂 JavaScript is not fault tolerant
With HTML and CSS you’re
relying on the user agent to
do the right thing…🙁
Using JavaScript, you have a
means to test if what you’re
trying to do succeeded…✅
Predicting things is tough…
🔮
That’s why progressive
enhancement was a great
idea to solve this issue…
But is it still enough?
🔬
And what does it mean?
🤔
JavaScript can’t be trusted and
can be turned off.
💣
Everybody has JavaScript, and
we can do everything with it?
🔨
!
Story time…🐷*3🐺+🏠+🌳
https://a-k-apart.com/
Excellent, let’s do this!
https://codepo8.github.io/10kb-CSS-colour-game/
That was fun…
😎 Written on a plane, offline and in
roughly two hours
😎 Works on desktop and mobile,
independent of input and is
responsive
😎 All in all < 8 kb with the biggest
part being icons
https://codepo8.github.io/10kb-CSS-colour-game/
Well done, Chris!
https://www.google.com/patents/US4608967
Here’s the source… …Luke?
The structure was not hard…
😎 Have an array of all the possible colours.
😎 Get a random cut of n elements, display them as a list; store the name of the colour
as a data attribute
😎 Get one item of the list as the colour to match, show its name.
😎 Use event delegation on the list to add one click handler (also allows for keyboard)
😎 Compare the data attribute of the target of the event with the colour to match
😎 If true, display a new random list
😎 If false, decrease the possible moves counter
😎 If no more moves left, show game over
💩 Only issue: there is no array_rand()
Computers and smartphones are
powerful.
Browsers can do a lot and are open to
feedback.
JavaScript is flexible and has evolved.
CSS has become amazing.
Developer tools in browsers give us great
debugging and even design capabilities
😍
🦄
🎉
The beauty of HTML, CSS and JS…
😍 All is contained in one package
😍 Everything is running on the end users
environments
😍 You use what the OS and the hardware gives
you. It can be a web site or an app,
depending on who runs it where
😍 You wouldn’t even need ServiceWorker to
make this work offline - inlining everything
would be enough
📦
Then I read the contest
guidelines…
😟
https://a-k-apart.com/faq http://stateofjs.com/
I FAQed up…
😭
Should I try to make this
a NodeJS, universal,
functional, gluten-free…🤔
Sod it, I know PHP…
🤓
New, more sturdy structure…
😎 Write a PHP API with the named colours as the content
😎 Use array_rand() to get a cut of that, pick one as the one to match
😎 Write out a list of buttons with the same name and the colour as the value.
😎 If the colour matches the button that was clicked, get a new list
😎 If the colour doesn’t match, decrease the amount of moves and show the list again.
😠 Oh, crap…
As we don’t keep the
state of the game in the
browser, I need to
maintain the random
array in between
reloads…
👜
The amount is not much,
but you better make sure
that there is no way to
inject code to the server.
🚨
Leveling up your JavaScipt - DrupalJam 2017
Constant vigilance,
Harry…
Now it works without JS, let’s add some…
😎 Load the API content with AJAX
🤔 Repeat the rest of the functionality client-side, or do
a lot of unnecessary server roundtrips…
🍕
The better, sturdier, more webby version
🤔 Almost same amount of
JavaScript content
🤔 Doesn’t work offline, unless
we also create a different
API
🤔 But it does work with
JavaScript disabled.
😨 It also allows bad people
to inject code unless we
are very vigilant in keeping
our backend secure.
How about some heresy?
😯
The “JavaScript not available”
argument is largely bogus
and is holding back the web!
➡
🎤
The “JavaScript is flaky and
will break” argument is very
much alive and will always be
that way…
🚧
Until the first successful load,
you have no JavaScript
functionality. That is a fact.B
We call this “programming”
C
🖥→💻→📱
Evolution is happening around us…
…and user numbers are shifting.
This means that new error
cases become much more
important than “JavaScript is
not available”
⚠
✏ Small initial payload
✏ Form factor supporting content
✏ Form factor supporting interfaces
✏ Offline/Flaky connection support
✏ Taking advantage of the power of
the end user device
✏ Avoiding interaction latency
❤📲
This is achievable using
HTML, JavaScript and CSS,
but it is much harder - if
not impossible - without
client side scripting.
👷
Which is annoying, as the
HTML5 revolution
promised a move from
documents to apps…
The problem is that eight
years after the proposal
and five years after
HTML5’s “last call”, there
are still many basic support
issues…
😦
https://vimeo.com/176453149
Monica Dinculescu < INPUT >
HTML Special, CSS Day
https://www.filamentgroup.com/lab/type-number.html
And the bad people of the
internet don’t stop abusing
old technology either…💀
In UGC, we can’t have nice things…
https://mathiasbynens.github.io/rel-noopener/
https://medium.com/@jitbit/target-blank-the-most-underestimated-vulnerability-ever-96e328301f4c#.mjuw7q3cf
Keep users on this page…
https://mathiasbynens.github.io/rel-noopener/
https://medium.com/@jitbit/target-blank-the-most-underestimated-vulnerability-ever-96e328301f4c#.mjuw7q3cf
🔓💩
Fix for newer browsers…
https://mathiasbynens.github.io/rel-noopener/
https://medium.com/@jitbit/target-blank-the-most-underestimated-vulnerability-ever-96e328301f4c#.mjuw7q3cf
Fix for all browsers…
https://mathiasbynens.github.io/rel-noopener/
https://medium.com/@jitbit/target-blank-the-most-underestimated-vulnerability-ever-96e328301f4c#.mjuw7q3cf
Almost…
Listen for the click event and prevent the default
browser behavior of opening a new tab. Inject a
hidden iframe that opens the new tab, then
immediately remove the iframe.“
https://github.com/danielstjules/blankshield
Our solutions should have
excellent error handling
instead of automatic
tolerance.
👌
And they should be great
solutions and not just
“good enough without
breaking”.
https://twitter.com/dieni/status/767589581046841344
Non-defensive coding is a problem…
We all make mistakes and errors happen…
There is a culture of “let’s
use whatever until it works”
😐
Standing on the shoulders of… …people?
http://status.npmjs.org/incidents/dw8cr1lwxkcr
http://status.npmjs.org/incidents/dw8cr1lwxkcr
http://status.npmjs.org/incidents/dw8cr1lwxkcr
Better be safe and require()…
More detail: the "fs" package is a non-functional
package. It simply logs the word "I am fs" and exits.
There is no reason it should be included in any
modules. However, something like 1000 packages *do*
mistakenly depend on "fs", probably because they were
trying to use a built-in node module called "fs".
This is not a JavaScript thing…
We have a lot of messy
solutions, and we keep
building more tools to undo
what clogs up the web.
Best practices can help with
that, but only when they
apply to the people who
build things and when they
solve current issues and
needs…
What about older browsers?
What about extreme
environment browsers?
These are valid concerns,
but edge cases. And
shouldn’t be used as a
punishment scenario.
🗞
What about accessibility, eh?
♿
Used sensibly, JavaScript is an
accessibility benefit.
Sometimes the only way to
make things accessible. ARIA
is not magic.
🕹
https://codepo8.github.io/gridnav/
It is more important for us
to get a grip on the overall
quality of the web and our
code…
🏅
Using
instead of a URL or using a
button is not JavaScript’s fault.
It is a bad idea and practice -
probably copy & paste.
💩
<a href="javascript:void(0)">
Instead of bashing bad use
of JavaScript, let’s embrace
and scrutinise new ideas like
components and paradigms
like functional programming.
🔎
There is a very cool thing
happening right now…
😃
Service Worker & PWAs
https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API
🔧 🦄
Making the game an App: Manifest
App Manifest (manifest.json)
Using a manifest, the game is
recognised by OS and search engines
as an installable app
Service Worker (sw.js)
Using ServiceWorker to cache content
locally so the game can be played
offline.
Making the game an App: Service Worker
Making the game an App: Service Worker
Service Worker (sw.js)
Using ServiceWorker to cache content
locally so the game can be played
offline.
✅ Create and publish as much content
independent of JavaScript as you can
✅ JavaScript can make things much more
enjoyable.
✅ Some things are just not worth while to
implement without.
✅ Use JavaScript to benefit from the user’s
hardware
✅ Spend more time building great
interfaces, less time relying on what is
there and can’t break - in many cases it
is disappointing.
It is time to re-
think our best
practice for the
web approach…
🙂 You don’t rely on automatic fixes.
JavaScript breaks and it is painful. It
allows us to analyse what went wrong.
🙂 Tooling is great - we detailed insights
into what happened when
🙂 We take responsibility of the interface. It
is our job to make it happen - not
browser makers to agree and find a
consensus
🙂 We have full control over what gets
loaded when, cached where and
rendered when.
Benefits of an “It’s
OK to rely on JS
for this”
approach…
⚠ We shouldn’t hide functionality in
magical abstractions. A product that
relies on the availability and maintenance
of a framework is not a script
dependency - it is a support issue.
⚠ Just because we can do everything in
JavaScript, doesn’t mean we have to. Use
it when HTML is not good enough or too
broken to rely on.
⚠ While the client is powerful, it is also
unknown. A lot more can be done on
the server - and in JavaScript.
Dangers to be
aware of…
Important
considerations
independent of
technology used…
💣 Shit happens! Spend more time in
creating sensible error messaging and
fallbacks, spend less time in trying to
predict every possible error
💣 Slowness kills - our solutions must load
fast what is needed and enhance when
they can. They also need to be snappy.
💣 Offline and flaky is the norm - avoid
network dependency as much as you
can
💣 Security is paramount. A hacked
server sending out malware or spam is
worse than an app that needs a
restart…
We have to stop thinking in
binaries, and consider writing
great, secure and failure-
aware solutions using each
technology to its strengths.
🐝
Mario evolved - so can the web…
CHRIS HEILMANN
@CODEPO8
CHRISTIANHEILMANN.COM
THANKS!
1 of 94

Recommended

Breaking out of the Tetris mind set #btconf by
Breaking out of the Tetris mind set #btconfBreaking out of the Tetris mind set #btconf
Breaking out of the Tetris mind set #btconfChristian Heilmann
3.2K views65 slides
Progressive Web Apps – the return of the web? by
Progressive Web Apps – the return of the web?Progressive Web Apps – the return of the web?
Progressive Web Apps – the return of the web?Christian Heilmann
1.5K views84 slides
Turning huge ships - Open Source and Microsoft by
Turning huge ships - Open Source and MicrosoftTurning huge ships - Open Source and Microsoft
Turning huge ships - Open Source and MicrosoftChristian Heilmann
654 views47 slides
CSS vs. JavaScript - Trust vs. Control by
CSS vs. JavaScript - Trust vs. ControlCSS vs. JavaScript - Trust vs. Control
CSS vs. JavaScript - Trust vs. ControlChristian Heilmann
1.5K views67 slides
Progressive Web Apps - Goto Chicago 2017 by
Progressive Web Apps - Goto Chicago 2017Progressive Web Apps - Goto Chicago 2017
Progressive Web Apps - Goto Chicago 2017Christian Heilmann
1.1K views86 slides
JavaScript is a buffet - Scriptconf 2017 keynote by
JavaScript is a buffet - Scriptconf 2017 keynoteJavaScript is a buffet - Scriptconf 2017 keynote
JavaScript is a buffet - Scriptconf 2017 keynoteChristian Heilmann
14.3K views82 slides

More Related Content

What's hot

The Soul in The Machine - Developing for Humans (FrankenJS edition) by
The Soul in The Machine - Developing for Humans (FrankenJS edition)The Soul in The Machine - Developing for Humans (FrankenJS edition)
The Soul in The Machine - Developing for Humans (FrankenJS edition)Christian Heilmann
916 views90 slides
Progressive Web Apps – the return of the web? Goto Berlin 2016 by
Progressive Web Apps – the return of the web? Goto Berlin 2016Progressive Web Apps – the return of the web? Goto Berlin 2016
Progressive Web Apps – the return of the web? Goto Berlin 2016Christian Heilmann
1K views74 slides
The Soul in The Machine - Developing for Humans by
The Soul in The Machine - Developing for HumansThe Soul in The Machine - Developing for Humans
The Soul in The Machine - Developing for HumansChristian Heilmann
1.4K views83 slides
Progressing JavaScript and Apps the Web way… by
 Progressing JavaScript and Apps the Web way…  Progressing JavaScript and Apps the Web way…
Progressing JavaScript and Apps the Web way… Christian Heilmann
1.6K views67 slides
The State of the Web - Helsinki meetup by
The State of the Web - Helsinki meetupThe State of the Web - Helsinki meetup
The State of the Web - Helsinki meetupChristian Heilmann
4K views70 slides
The image problem of the web and how to solve it… by
The image problem of the web and how to solve it…The image problem of the web and how to solve it…
The image problem of the web and how to solve it…Christian Heilmann
1.6K views58 slides

What's hot(20)

The Soul in The Machine - Developing for Humans (FrankenJS edition) by Christian Heilmann
The Soul in The Machine - Developing for Humans (FrankenJS edition)The Soul in The Machine - Developing for Humans (FrankenJS edition)
The Soul in The Machine - Developing for Humans (FrankenJS edition)
Christian Heilmann916 views
Progressive Web Apps – the return of the web? Goto Berlin 2016 by Christian Heilmann
Progressive Web Apps – the return of the web? Goto Berlin 2016Progressive Web Apps – the return of the web? Goto Berlin 2016
Progressive Web Apps – the return of the web? Goto Berlin 2016
The Soul in The Machine - Developing for Humans by Christian Heilmann
The Soul in The Machine - Developing for HumansThe Soul in The Machine - Developing for Humans
The Soul in The Machine - Developing for Humans
Christian Heilmann1.4K views
Progressing JavaScript and Apps the Web way… by Christian Heilmann
 Progressing JavaScript and Apps the Web way…  Progressing JavaScript and Apps the Web way…
Progressing JavaScript and Apps the Web way…
Christian Heilmann1.6K views
The image problem of the web and how to solve it… by Christian Heilmann
The image problem of the web and how to solve it…The image problem of the web and how to solve it…
The image problem of the web and how to solve it…
Christian Heilmann1.6K views
NodeConfLondon - Making ES6 happen with ChakraCore and Node by Christian Heilmann
NodeConfLondon - Making ES6 happen with ChakraCore and NodeNodeConfLondon - Making ES6 happen with ChakraCore and Node
NodeConfLondon - Making ES6 happen with ChakraCore and Node
Christian Heilmann3.1K views
Postmodern Web Apps by malteubl
Postmodern Web AppsPostmodern Web Apps
Postmodern Web Apps
malteubl14.2K views
2021 Chrome Dev Summit: Web Performance 101 by Tammy Everts
2021 Chrome Dev Summit: Web Performance 1012021 Chrome Dev Summit: Web Performance 101
2021 Chrome Dev Summit: Web Performance 101
Tammy Everts897 views
Moore vs. May - everything is faster and better: we can fix that by Christian Heilmann
Moore vs. May - everything is faster and better: we can fix thatMoore vs. May - everything is faster and better: we can fix that
Moore vs. May - everything is faster and better: we can fix that
Stapling and patching the web of now - ForwardJS3, San Francisco by Christian Heilmann
Stapling and patching the web of now - ForwardJS3, San FranciscoStapling and patching the web of now - ForwardJS3, San Francisco
Stapling and patching the web of now - ForwardJS3, San Francisco
Christian Heilmann12.9K views
Automating all the wrong things - You Gotta Love Frontend Keynote by Christian Heilmann
Automating all the wrong things - You Gotta Love Frontend KeynoteAutomating all the wrong things - You Gotta Love Frontend Keynote
Automating all the wrong things - You Gotta Love Frontend Keynote
Christian Heilmann798 views
Let’s learn how to use JavaScript responsibly and stay up-to-date. by Christian Heilmann
Let’s learn how to use JavaScript responsibly and stay up-to-date. Let’s learn how to use JavaScript responsibly and stay up-to-date.
Let’s learn how to use JavaScript responsibly and stay up-to-date.
Christian Heilmann4.5K views
Can we make es6 the baseline of the “modern web”? - BrazilJS 2105 by Christian Heilmann
Can we make es6 the baseline of the “modern web”? - BrazilJS 2105 Can we make es6 the baseline of the “modern web”? - BrazilJS 2105
Can we make es6 the baseline of the “modern web”? - BrazilJS 2105
Christian Heilmann5.3K views
Looking for a place to hang my helmet by Brad Frost
Looking for a place to hang my helmetLooking for a place to hang my helmet
Looking for a place to hang my helmet
Brad Frost20.6K views
Upgrading JavaScript to ES6 and using TypeScript as a shortcut by Christian Heilmann
Upgrading JavaScript to ES6 and using TypeScript as a shortcutUpgrading JavaScript to ES6 and using TypeScript as a shortcut
Upgrading JavaScript to ES6 and using TypeScript as a shortcut
Christian Heilmann709 views
The wheel is spinning but the hamster is almost dead - Smartweb 2015 by Christian Heilmann
The wheel is spinning but the hamster is almost dead - Smartweb 2015The wheel is spinning but the hamster is almost dead - Smartweb 2015
The wheel is spinning but the hamster is almost dead - Smartweb 2015
Christian Heilmann22.7K views

Similar to Leveling up your JavaScipt - DrupalJam 2017

Progressive web and the problem of JavaScript by
Progressive web and the problem of JavaScriptProgressive web and the problem of JavaScript
Progressive web and the problem of JavaScriptChristian Heilmann
6.1K views96 slides
JavaScript Promises and the issue of Progress - SmashingConf Freiburg Jam Ses... by
JavaScript Promises and the issue of Progress - SmashingConf Freiburg Jam Ses...JavaScript Promises and the issue of Progress - SmashingConf Freiburg Jam Ses...
JavaScript Promises and the issue of Progress - SmashingConf Freiburg Jam Ses...Christian Heilmann
435 views30 slides
Resisting The Feature Creature by
Resisting The Feature CreatureResisting The Feature Creature
Resisting The Feature CreatureChristian Heilmann
5.1K views61 slides
Academy PRO: HTML5 API graphics by
Academy PRO: HTML5 API graphicsAcademy PRO: HTML5 API graphics
Academy PRO: HTML5 API graphicsBinary Studio
147 views65 slides
Shifting Gears by
Shifting GearsShifting Gears
Shifting GearsChristian Heilmann
6.7K views130 slides
Look ma! No images! by
Look ma! No images!Look ma! No images!
Look ma! No images!Lennart Schoors
5K views36 slides

Similar to Leveling up your JavaScipt - DrupalJam 2017(20)

Progressive web and the problem of JavaScript by Christian Heilmann
Progressive web and the problem of JavaScriptProgressive web and the problem of JavaScript
Progressive web and the problem of JavaScript
Christian Heilmann6.1K views
JavaScript Promises and the issue of Progress - SmashingConf Freiburg Jam Ses... by Christian Heilmann
JavaScript Promises and the issue of Progress - SmashingConf Freiburg Jam Ses...JavaScript Promises and the issue of Progress - SmashingConf Freiburg Jam Ses...
JavaScript Promises and the issue of Progress - SmashingConf Freiburg Jam Ses...
Christian Heilmann435 views
Academy PRO: HTML5 API graphics by Binary Studio
Academy PRO: HTML5 API graphicsAcademy PRO: HTML5 API graphics
Academy PRO: HTML5 API graphics
Binary Studio147 views
Responsive Web Design: the secret sauce - JavaScript Open Day Montreal - 2015... by Frédéric Harper
Responsive Web Design: the secret sauce - JavaScript Open Day Montreal - 2015...Responsive Web Design: the secret sauce - JavaScript Open Day Montreal - 2015...
Responsive Web Design: the secret sauce - JavaScript Open Day Montreal - 2015...
Frédéric Harper872 views
Javascript Animation with Canvas - Gregory Starr 2015 by Gregory Starr
Javascript Animation with Canvas - Gregory Starr 2015Javascript Animation with Canvas - Gregory Starr 2015
Javascript Animation with Canvas - Gregory Starr 2015
Gregory Starr1.1K views
AFUP Lorraine - Symfony Webpack Encore by Engineor
AFUP Lorraine - Symfony Webpack EncoreAFUP Lorraine - Symfony Webpack Encore
AFUP Lorraine - Symfony Webpack Encore
Engineor356 views
Bridging the gap between designers and developers at theguardian.com by Kaelig Deloumeau-Prigent
Bridging the gap between designers and developers at theguardian.comBridging the gap between designers and developers at theguardian.com
Bridging the gap between designers and developers at theguardian.com
Ruby on Rails - The Best Track for your Start Up by Prateek Saxena
Ruby on Rails - The Best Track for your Start UpRuby on Rails - The Best Track for your Start Up
Ruby on Rails - The Best Track for your Start Up
Prateek Saxena2.9K views
Responsive Design by David Hudson
Responsive DesignResponsive Design
Responsive Design
David Hudson1.9K views
Introjs10.5.17SD by Thinkful
Introjs10.5.17SDIntrojs10.5.17SD
Introjs10.5.17SD
Thinkful99 views
Responsive Web Design, get the best out of your designs - JavaScript Open Day... by Frédéric Harper
Responsive Web Design, get the best out of your designs - JavaScript Open Day...Responsive Web Design, get the best out of your designs - JavaScript Open Day...
Responsive Web Design, get the best out of your designs - JavaScript Open Day...
Frédéric Harper6.7K views

More from Christian Heilmann

Develop, Debug, Learn? - Dotjs2019 by
Develop, Debug, Learn? - Dotjs2019Develop, Debug, Learn? - Dotjs2019
Develop, Debug, Learn? - Dotjs2019Christian Heilmann
1.1K views55 slides
Hinting at a better web by
Hinting at a better webHinting at a better web
Hinting at a better webChristian Heilmann
2.8K views33 slides
Taking the "vile" out of privilege by
Taking the "vile" out of privilegeTaking the "vile" out of privilege
Taking the "vile" out of privilegeChristian Heilmann
1K views64 slides
Seven ways to be a happier JavaScript developer - NDC Oslo by
Seven ways to be a happier JavaScript developer - NDC OsloSeven ways to be a happier JavaScript developer - NDC Oslo
Seven ways to be a happier JavaScript developer - NDC OsloChristian Heilmann
1.5K views52 slides
Artificial intelligence for humans… #AIDC2018 keynote by
Artificial intelligence for humans… #AIDC2018 keynoteArtificial intelligence for humans… #AIDC2018 keynote
Artificial intelligence for humans… #AIDC2018 keynoteChristian Heilmann
1.2K views56 slides
Killing the golden calf of coding - We are Developers keynote by
Killing the golden calf of coding - We are Developers keynoteKilling the golden calf of coding - We are Developers keynote
Killing the golden calf of coding - We are Developers keynoteChristian Heilmann
3.1K views35 slides

More from Christian Heilmann(20)

Seven ways to be a happier JavaScript developer - NDC Oslo by Christian Heilmann
Seven ways to be a happier JavaScript developer - NDC OsloSeven ways to be a happier JavaScript developer - NDC Oslo
Seven ways to be a happier JavaScript developer - NDC Oslo
Christian Heilmann1.5K views
Artificial intelligence for humans… #AIDC2018 keynote by Christian Heilmann
Artificial intelligence for humans… #AIDC2018 keynoteArtificial intelligence for humans… #AIDC2018 keynote
Artificial intelligence for humans… #AIDC2018 keynote
Christian Heilmann1.2K views
Killing the golden calf of coding - We are Developers keynote by Christian Heilmann
Killing the golden calf of coding - We are Developers keynoteKilling the golden calf of coding - We are Developers keynote
Killing the golden calf of coding - We are Developers keynote
Christian Heilmann3.1K views
Five ways to be a happier JavaScript developer by Christian Heilmann
Five ways to be a happier JavaScript developerFive ways to be a happier JavaScript developer
Five ways to be a happier JavaScript developer
Christian Heilmann859 views
Progressive Web Apps - Covering the best of both worlds - DevReach by Christian Heilmann
Progressive Web Apps - Covering the best of both worlds - DevReachProgressive Web Apps - Covering the best of both worlds - DevReach
Progressive Web Apps - Covering the best of both worlds - DevReach
Christian Heilmann956 views
Progressive Web Apps - Covering the best of both worlds by Christian Heilmann
Progressive Web Apps - Covering the best of both worldsProgressive Web Apps - Covering the best of both worlds
Progressive Web Apps - Covering the best of both worlds
Christian Heilmann799 views
Non-trivial pursuits: Learning machines and forgetful humans by Christian Heilmann
Non-trivial pursuits: Learning machines and forgetful humansNon-trivial pursuits: Learning machines and forgetful humans
Non-trivial pursuits: Learning machines and forgetful humans
Christian Heilmann531 views
Progressive Web Apps - Bringing the web front and center by Christian Heilmann
Progressive Web Apps - Bringing the web front and center Progressive Web Apps - Bringing the web front and center
Progressive Web Apps - Bringing the web front and center
Christian Heilmann1.2K views
Suit up, bring extra oxygen Internet space explorers needed. by Christian Heilmann
Suit up, bring extra oxygen Internet space explorers needed.Suit up, bring extra oxygen Internet space explorers needed.
Suit up, bring extra oxygen Internet space explorers needed.
Christian Heilmann2.6K views
Microsoft und die Open Source Community - Leaving the death star behind by Christian Heilmann
Microsoft und die Open Source Community - Leaving the death star behindMicrosoft und die Open Source Community - Leaving the death star behind
Microsoft und die Open Source Community - Leaving the death star behind
Christian Heilmann1.2K views

Recently uploaded

Pandit No2 Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam... by
Pandit No2 Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam...Pandit No2 Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam...
Pandit No2 Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam...Amil baba
6 views1 slide
Teaching Third Generation Islamic Economics by
Teaching Third Generation Islamic EconomicsTeaching Third Generation Islamic Economics
Teaching Third Generation Islamic EconomicsAsad Zaman
197 views37 slides
Stock Market Brief Deck 121.pdf by
Stock Market Brief Deck 121.pdfStock Market Brief Deck 121.pdf
Stock Market Brief Deck 121.pdfMichael Silva
30 views52 slides
Practices of corporate governance in Commercial Banks of Bangladesh by
Practices of corporate governance in Commercial Banks of BangladeshPractices of corporate governance in Commercial Banks of Bangladesh
Practices of corporate governance in Commercial Banks of BangladeshAriful Saimon
5 views81 slides
Motilal Oswal Small Cap Fund One Pager.pdf by
Motilal Oswal Small Cap Fund One Pager.pdfMotilal Oswal Small Cap Fund One Pager.pdf
Motilal Oswal Small Cap Fund One Pager.pdfmultigainfinancial
71 views2 slides
Embracing the eFarming Challenge.pdf by
Embracing the eFarming Challenge.pdfEmbracing the eFarming Challenge.pdf
Embracing the eFarming Challenge.pdframadhan04116
5 views1 slide

Recently uploaded(20)

Pandit No2 Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam... by Amil baba
Pandit No2 Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam...Pandit No2 Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam...
Pandit No2 Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam...
Amil baba6 views
Teaching Third Generation Islamic Economics by Asad Zaman
Teaching Third Generation Islamic EconomicsTeaching Third Generation Islamic Economics
Teaching Third Generation Islamic Economics
Asad Zaman197 views
Stock Market Brief Deck 121.pdf by Michael Silva
Stock Market Brief Deck 121.pdfStock Market Brief Deck 121.pdf
Stock Market Brief Deck 121.pdf
Michael Silva30 views
Practices of corporate governance in Commercial Banks of Bangladesh by Ariful Saimon
Practices of corporate governance in Commercial Banks of BangladeshPractices of corporate governance in Commercial Banks of Bangladesh
Practices of corporate governance in Commercial Banks of Bangladesh
Ariful Saimon5 views
Embracing the eFarming Challenge.pdf by ramadhan04116
Embracing the eFarming Challenge.pdfEmbracing the eFarming Challenge.pdf
Embracing the eFarming Challenge.pdf
ramadhan041165 views
The breath of the investment grade and the unpredictability of inflation - Eu... by Antonis Zairis
The breath of the investment grade and the unpredictability of inflation - Eu...The breath of the investment grade and the unpredictability of inflation - Eu...
The breath of the investment grade and the unpredictability of inflation - Eu...
Antonis Zairis7 views
Macro Economics- Group Presentation for Germany by BethanyAline
Macro Economics- Group Presentation for Germany Macro Economics- Group Presentation for Germany
Macro Economics- Group Presentation for Germany
BethanyAline38 views
Topic 37 copy.pptx by saleh176
Topic 37 copy.pptxTopic 37 copy.pptx
Topic 37 copy.pptx
saleh1765 views
1_updated_Axis India Manufacturing Fund-NFO One pager.pdf by multigainfinancial
1_updated_Axis India Manufacturing Fund-NFO One pager.pdf1_updated_Axis India Manufacturing Fund-NFO One pager.pdf
1_updated_Axis India Manufacturing Fund-NFO One pager.pdf
Blockchain, AI & Metaverse for Football Clubs - 2023.pdf by kelroyjames1
Blockchain, AI & Metaverse for Football Clubs - 2023.pdfBlockchain, AI & Metaverse for Football Clubs - 2023.pdf
Blockchain, AI & Metaverse for Football Clubs - 2023.pdf
kelroyjames110 views
score 10000.pdf by sadimd007
score 10000.pdfscore 10000.pdf
score 10000.pdf
sadimd00710 views
Stock Market Brief Deck 1129.pdf by Michael Silva
Stock Market Brief Deck 1129.pdfStock Market Brief Deck 1129.pdf
Stock Market Brief Deck 1129.pdf
Michael Silva53 views
TriStar Gold- Corporate Presentation - December 2023 by Adnet Communications
TriStar Gold- Corporate Presentation - December 2023TriStar Gold- Corporate Presentation - December 2023
TriStar Gold- Corporate Presentation - December 2023
Indias Sparkling Future : Lab-Grown Diamonds in Focus by anujadeodhar4
Indias Sparkling Future : Lab-Grown Diamonds in FocusIndias Sparkling Future : Lab-Grown Diamonds in Focus
Indias Sparkling Future : Lab-Grown Diamonds in Focus
anujadeodhar47 views

Leveling up your JavaScipt - DrupalJam 2017

  • 1. Chris Heilmann @codepo8, DrupalJam, May 2017
  • 2. Of innovation and impatience Chris Heilmann @codepo8, Future Decoded, London, Nov 2015 CHRIS HEILMANN @CODEPO8
  • 4. We all know this character, right? https://en.wikipedia.org/wiki/Mario#Concept_and_creation
  • 5. But do you know why it looks like it does? https://en.wikipedia.org/wiki/Mario#Concept_and_creation
  • 6. Red and Blue offered the best contrast to the skin, boots and the game background. https://en.wikipedia.org/wiki/Mario#Concept_and_creation
  • 7. The cap meant there was no need to worry about hair style, eyebrows and forehead. (There were also not enough pixels for waving hair when falling down a hole)
  • 8. The large nose and moustache made it possible to avoid a mouth and facial expressions.
  • 10. Design by lack of definition. 🌎🕸
  • 11. Flexibility and forgiveness… 💧 HTML and CSS are fault tolerant…
  • 12. Knives, bees and footguns… 🦂 JavaScript is not fault tolerant
  • 13. With HTML and CSS you’re relying on the user agent to do the right thing…🙁
  • 14. Using JavaScript, you have a means to test if what you’re trying to do succeeded…✅
  • 15. Predicting things is tough… 🔮
  • 16. That’s why progressive enhancement was a great idea to solve this issue…
  • 17. But is it still enough? 🔬
  • 18. And what does it mean? 🤔
  • 19. JavaScript can’t be trusted and can be turned off. 💣
  • 20. Everybody has JavaScript, and we can do everything with it? 🔨
  • 21. !
  • 24. Excellent, let’s do this! https://codepo8.github.io/10kb-CSS-colour-game/
  • 25. That was fun… 😎 Written on a plane, offline and in roughly two hours 😎 Works on desktop and mobile, independent of input and is responsive 😎 All in all < 8 kb with the biggest part being icons https://codepo8.github.io/10kb-CSS-colour-game/
  • 28. The structure was not hard… 😎 Have an array of all the possible colours. 😎 Get a random cut of n elements, display them as a list; store the name of the colour as a data attribute 😎 Get one item of the list as the colour to match, show its name. 😎 Use event delegation on the list to add one click handler (also allows for keyboard) 😎 Compare the data attribute of the target of the event with the colour to match 😎 If true, display a new random list 😎 If false, decrease the possible moves counter 😎 If no more moves left, show game over 💩 Only issue: there is no array_rand()
  • 29. Computers and smartphones are powerful. Browsers can do a lot and are open to feedback. JavaScript is flexible and has evolved. CSS has become amazing. Developer tools in browsers give us great debugging and even design capabilities 😍 🦄 🎉
  • 30. The beauty of HTML, CSS and JS… 😍 All is contained in one package 😍 Everything is running on the end users environments 😍 You use what the OS and the hardware gives you. It can be a web site or an app, depending on who runs it where 😍 You wouldn’t even need ServiceWorker to make this work offline - inlining everything would be enough 📦
  • 31. Then I read the contest guidelines… 😟
  • 34. Should I try to make this a NodeJS, universal, functional, gluten-free…🤔
  • 35. Sod it, I know PHP… 🤓
  • 36. New, more sturdy structure… 😎 Write a PHP API with the named colours as the content 😎 Use array_rand() to get a cut of that, pick one as the one to match 😎 Write out a list of buttons with the same name and the colour as the value. 😎 If the colour matches the button that was clicked, get a new list 😎 If the colour doesn’t match, decrease the amount of moves and show the list again. 😠 Oh, crap…
  • 37. As we don’t keep the state of the game in the browser, I need to maintain the random array in between reloads… 👜
  • 38. The amount is not much, but you better make sure that there is no way to inject code to the server. 🚨
  • 41. Now it works without JS, let’s add some… 😎 Load the API content with AJAX 🤔 Repeat the rest of the functionality client-side, or do a lot of unnecessary server roundtrips… 🍕
  • 42. The better, sturdier, more webby version 🤔 Almost same amount of JavaScript content 🤔 Doesn’t work offline, unless we also create a different API 🤔 But it does work with JavaScript disabled. 😨 It also allows bad people to inject code unless we are very vigilant in keeping our backend secure.
  • 43. How about some heresy? 😯
  • 44. The “JavaScript not available” argument is largely bogus and is holding back the web! ➡ 🎤
  • 45. The “JavaScript is flaky and will break” argument is very much alive and will always be that way… 🚧
  • 46. Until the first successful load, you have no JavaScript functionality. That is a fact.B
  • 47. We call this “programming” C
  • 48. 🖥→💻→📱 Evolution is happening around us… …and user numbers are shifting.
  • 49. This means that new error cases become much more important than “JavaScript is not available” ⚠
  • 50. ✏ Small initial payload ✏ Form factor supporting content ✏ Form factor supporting interfaces ✏ Offline/Flaky connection support ✏ Taking advantage of the power of the end user device ✏ Avoiding interaction latency ❤📲
  • 51. This is achievable using HTML, JavaScript and CSS, but it is much harder - if not impossible - without client side scripting. 👷
  • 52. Which is annoying, as the HTML5 revolution promised a move from documents to apps…
  • 53. The problem is that eight years after the proposal and five years after HTML5’s “last call”, there are still many basic support issues… 😦
  • 54. https://vimeo.com/176453149 Monica Dinculescu < INPUT > HTML Special, CSS Day
  • 56. And the bad people of the internet don’t stop abusing old technology either…💀
  • 57. In UGC, we can’t have nice things… https://mathiasbynens.github.io/rel-noopener/ https://medium.com/@jitbit/target-blank-the-most-underestimated-vulnerability-ever-96e328301f4c#.mjuw7q3cf
  • 58. Keep users on this page… https://mathiasbynens.github.io/rel-noopener/ https://medium.com/@jitbit/target-blank-the-most-underestimated-vulnerability-ever-96e328301f4c#.mjuw7q3cf 🔓💩
  • 59. Fix for newer browsers… https://mathiasbynens.github.io/rel-noopener/ https://medium.com/@jitbit/target-blank-the-most-underestimated-vulnerability-ever-96e328301f4c#.mjuw7q3cf
  • 60. Fix for all browsers… https://mathiasbynens.github.io/rel-noopener/ https://medium.com/@jitbit/target-blank-the-most-underestimated-vulnerability-ever-96e328301f4c#.mjuw7q3cf
  • 61. Almost… Listen for the click event and prevent the default browser behavior of opening a new tab. Inject a hidden iframe that opens the new tab, then immediately remove the iframe.“ https://github.com/danielstjules/blankshield
  • 62. Our solutions should have excellent error handling instead of automatic tolerance. 👌
  • 63. And they should be great solutions and not just “good enough without breaking”. https://twitter.com/dieni/status/767589581046841344
  • 64. Non-defensive coding is a problem…
  • 65. We all make mistakes and errors happen…
  • 66. There is a culture of “let’s use whatever until it works” 😐
  • 67. Standing on the shoulders of… …people?
  • 70. http://status.npmjs.org/incidents/dw8cr1lwxkcr Better be safe and require()… More detail: the "fs" package is a non-functional package. It simply logs the word "I am fs" and exits. There is no reason it should be included in any modules. However, something like 1000 packages *do* mistakenly depend on "fs", probably because they were trying to use a built-in node module called "fs".
  • 71. This is not a JavaScript thing…
  • 72. We have a lot of messy solutions, and we keep building more tools to undo what clogs up the web.
  • 73. Best practices can help with that, but only when they apply to the people who build things and when they solve current issues and needs…
  • 74. What about older browsers?
  • 76. These are valid concerns, but edge cases. And shouldn’t be used as a punishment scenario. 🗞
  • 78. Used sensibly, JavaScript is an accessibility benefit. Sometimes the only way to make things accessible. ARIA is not magic. 🕹
  • 80. It is more important for us to get a grip on the overall quality of the web and our code… 🏅
  • 81. Using instead of a URL or using a button is not JavaScript’s fault. It is a bad idea and practice - probably copy & paste. 💩 <a href="javascript:void(0)">
  • 82. Instead of bashing bad use of JavaScript, let’s embrace and scrutinise new ideas like components and paradigms like functional programming. 🔎
  • 83. There is a very cool thing happening right now… 😃
  • 84. Service Worker & PWAs https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API 🔧 🦄
  • 85. Making the game an App: Manifest App Manifest (manifest.json) Using a manifest, the game is recognised by OS and search engines as an installable app
  • 86. Service Worker (sw.js) Using ServiceWorker to cache content locally so the game can be played offline. Making the game an App: Service Worker
  • 87. Making the game an App: Service Worker Service Worker (sw.js) Using ServiceWorker to cache content locally so the game can be played offline.
  • 88. ✅ Create and publish as much content independent of JavaScript as you can ✅ JavaScript can make things much more enjoyable. ✅ Some things are just not worth while to implement without. ✅ Use JavaScript to benefit from the user’s hardware ✅ Spend more time building great interfaces, less time relying on what is there and can’t break - in many cases it is disappointing. It is time to re- think our best practice for the web approach…
  • 89. 🙂 You don’t rely on automatic fixes. JavaScript breaks and it is painful. It allows us to analyse what went wrong. 🙂 Tooling is great - we detailed insights into what happened when 🙂 We take responsibility of the interface. It is our job to make it happen - not browser makers to agree and find a consensus 🙂 We have full control over what gets loaded when, cached where and rendered when. Benefits of an “It’s OK to rely on JS for this” approach…
  • 90. ⚠ We shouldn’t hide functionality in magical abstractions. A product that relies on the availability and maintenance of a framework is not a script dependency - it is a support issue. ⚠ Just because we can do everything in JavaScript, doesn’t mean we have to. Use it when HTML is not good enough or too broken to rely on. ⚠ While the client is powerful, it is also unknown. A lot more can be done on the server - and in JavaScript. Dangers to be aware of…
  • 91. Important considerations independent of technology used… 💣 Shit happens! Spend more time in creating sensible error messaging and fallbacks, spend less time in trying to predict every possible error 💣 Slowness kills - our solutions must load fast what is needed and enhance when they can. They also need to be snappy. 💣 Offline and flaky is the norm - avoid network dependency as much as you can 💣 Security is paramount. A hacked server sending out malware or spam is worse than an app that needs a restart…
  • 92. We have to stop thinking in binaries, and consider writing great, secure and failure- aware solutions using each technology to its strengths. 🐝
  • 93. Mario evolved - so can the web…