Successfully reported this slideshow.
Activate your 14 day free trial to unlock unlimited reading.
Excellent, let’s do this!
That was fun…
😎 Written on a plane, offline and in
roughly two hours
😎 Works on desktop and mobile,
independent of input and is
😎 Using ServiceWorker caches
content locally and can be played
😎 All in all < 8 kb with the biggest
part being iconshttps://codepo8.github.io/10kb-CSS-colour-game/
Well done, Chris!
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
Browsers can do a lot and are open to
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
😍 You wouldn’t even need ServiceWorker to
make this work offline - inlining everything
would be enough
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
The amount is not much,
but you better make sure
that there is no way to
inject code to the server.
Now it works without JS, let’s add some…
😎 Load the API content with Francis, err… 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
🤔 Doesn’t work offline, unless
we also create a different
🤔 But it does work with
😨 It also allows bad people
to inject code unless we
are very vigilant in keeping
our backend secure.
Evolution is happening around us…
…and user numbers are shifting.
This means that new error
cases become much more
✏ 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
but it is much harder - if
not impossible - without
client side scripting.
Which is annoying, as the
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
Monica Dinculescu < INPUT >
HTML Special, CSS Day
And the bad people of the
internet don’t stop abusing
old technology either…💀
In UGC, we can’t have nice things…
Keep users on this page…
Fix for newer browsers…
Fix for all browsers…
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.“
Our solutions should have
excellent error handling
instead of automatic
And they should be great
solutions and not just
“good enough without
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".
Service Worker & PWAs
✅ Create and publish as much content
enjoyable and some things are just not
worth while to implement without.
✅ Spend more time building great
interfaces, less time relying on what is
there and can’t break - in many cases it
It is time to re-
think our best
practice for the
🙂 You don’t rely on automatic fixes.
allows us to analyse what went wrong.
🙂 Tooling is much better and we get much
more insights into what happened than
with, for example, CSS
🙂 We take responsibility of the interface. It
is our job to make it happen - not
browser makers to agree and find a
🙂 We have full control over what gets
loaded when, cached where and
Benefits of an “It’s
OK to rely on JS
⚠ 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
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
Dangers to be
💣 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
💣 Security is paramount. A hacked
server sending out malware or spam is
worse than an app that needs a
We have to stop thinking in
binaries, and consider writing
great, secure and failure-
aware solutions using each
technology to its strengths.