Today’s Readings

Two big release updates this past week:

  1. jQuery has released two new Alpha versions: 3.0 (for IE9+) and 3.0 Compat (for IE<9). There are several updates that could break existing code, but as usual, they are well documented, and jQuery Migrate should help you find any potential stress points.
  2. While not a major release like jQuery, WordPress 4.3.3 Beta was also released. In addition to several bug fixes, there are also a few improvements that have landed.

You may have heard that a short while ago left Google to join Fastly. Well, he has now also left Fastly to join SpeedCurve.

SpeedCurve leverages WebPageTest’s great data while making it significantly easier for you to use.

I was quite excited about the concept of PostCSS when I first heard about it, but the idea of restructuring all of my current workflows just wasn’t very appealing… Apparently I wasn’t the only one, as writes It’s Time for Everyone to Learn About PostCSS: What It Really Is; What It Really Does after having the same feelings, but making the leap anyway.

How to Debug JavaScript Remotely With Vorlon.js. Is this the next step after Weinre?

offers up a cool effect, using CSS transforms to augment photos. The initial image in the article is very cool, and actually caught me off-guard at first… :-)

Anyone working remotely, as in, not in the same office as everyone else (even just on some days)? If so, here are several tips to make remote working an easier, more productive experience for the whole team. I’d like to personally +1 that “be prepared” thingy…

Styling SVG<use> Content with CSS, by who else but , is much more than the title indicates, getting into how you should structure your code, how the browser creates the Shadow DOM, dealing with cascades and overrides, using tricks like all and currentColor, and even getting into what’s coming down the pipe, like CSS variables… Oh yeah, Sara also talks about styling SVG <use> content with CSS… :-)

A nice collection of things you should already know about responsive web development, but it is nice to see it all pulled together into a single place like this.

And pushing those last two bits together, here is a quick run-through on making sure your SVGs are responsive·

‘s latest Web Developer Reading List: Text Effects covers the gambit of text effects, from text shadows and strokes to neon signs and exploding text…

The Front-End Developer’s Dilemma by is very dear to my heart. I used to just tell people I do “computer crap” and would then expand on that incrementally until I felt they realized enough about technology that I could really explain what I do without making their eyes roll into the back of their heads: “I do web stuff.” “I’m a web developer.” “I do front-end development.” “I specialize in HTML, CSS, and JS, but work with WP and even SVG a good bit too, but I also think about and push-back a lot when it comes to UI and UX.” Having to explain the difference between web design and web development always surprises me, but I am the first to admit that I am not, and correct others when they wrongly label me as, a programmer; I know dudes that are computer programmers, and that is not me… :-)

Some complex-as-hell CSS selectors in this Quantity Ordering With CSS article… Whew!

And finally, ‘s “Tediously Accurate Map of the Solar System is mind-bogglingly, brain-numbingly, cortex-meltingly amazing… I admit I did not make it all the way to Pluto… After an insane amount of scrolling, I had passed Saturn (no, I did not make it to Uranus, snarf! ;-), yet my horizontal scroll bar said I was still only halfway… I got new respect for you, New Horizons

Happy reading,
Atg

The difference between Service Workers, Web Workers and WebSockets

As fairly-new web technologies, Service Workers, Web Workers and WebSockets all started, stalled, and then sort of made a resurgence. And so I find myself somewhat confused by exactly what each does, what the differences between them are, and what purpose each ideally serves.

I tried searching for some comparison articles, but was surprised by the lack of search results comparing all three of these technologies. I found two that come close…

  1. Getting Things Done with WebSockets and Web Workers is an online chapter from Learning HTML5 Game Programming.
  2. Ajax vs. Web sockets vs. Web Workers is a StackOverflow article.

…but neither compares the three I was curious about… So I decided to get to know them all a little better and document my findings here (so I could come back and remind myself again later…).

TL;DR

  • Service Worker:
    Background service that handles network requests. Ideal for dealing with offline situations and background syncs or push notifications. Cannot directly interact with the DOM. Communication must go through the Service Worker’s postMessage method.
  • Web Worker:
    Mimics multithreading, allowing intensive scripts to be run in the background so they do not block other scripts from running. Ideal for keeping your UI responsive while also performing processor-intensive functions. Cannot directly interact with the DOM. Communication must go through the Web Worker’s postMessage method.
  • WebSocket:
    Creates an open connection between a client and a server, allowing persistent two-way communication over a single connection. Ideal for any situation where you currently use long-polling such as chat apps, online games, or sports tickers. Can directly interact with the DOM. Communication is handled through the WebSocket’s send method.

NTL;WR ;-)

Service Workers

HTML5 Rocks has a nice introduction to Service Workers (aka ServiceWorkers). From that article, the best one-line definition I found was:

Service worker is a programmable network proxy, allowing you to control how network requests from your page are handled.

Service Workers are pretty perfect for creating offline-first web apps. They let you interact with the server when you can (to fetch new data from the server, or push updated info back to the server), so your app can work regardless of your user’s connectivity.

For example, an email client could fetch emails when the app loads, then, if the user loses connectivity for a brief period, the app could still continue to register read/unread and deleted states and store new emails to send until connectivity is restored, then send those updates back to the server via a Service Worker. To the user, all the time they were offline, the app continued to work, so they “got stuff done”, and your app just did its job, by collecting changes and updating the server as soon as it could.

While Service Workers cannot directly interact with the DOM, your main JS code can do that based on the messages you receive back from a Service Worker. Service workers also stop when not being used and restart when needed, so there is no persistent “state”; you would need to rely on some form of local storage (localStorage, IndexedDB, etc.) for such persistence. It is important to remember that a Service Worker’s life cycle is completely separate from your webpage.

You can dig a little more deeply into Service Workers, but apparently there is a law that anything published on the web about Service Workers must be created by . :-) That, or he is seriously, madly in love with them. (So much so that, while I would normally use Can I Use to determine the usability of Service Workers, even the Can I Use Service Workers table refers to Jake’s “Is Service Worker Ready?” page to find out the status of Service Workers…)

Service Worker resources:

Web Workers

HTML5 Rocks has a nice introduction to Web Workers (aka Workers). From that article, the best one-line definition I found was:

Workers utilize thread-like message passing to achieve parallelism.

Web Workers are pretty perfect for any web app that has intense functions to perform. They let you push the intense functions into a background thread so your main JS can keep on rocking, like maybe setting up event listeners and other UI interactions. Then, when the intense functions are done, they report back with their results, letting the main JS update the web app.

For example, a site that fetches and displays data in a series of dynamic charts could have each chart fetch its own data via a separate Web Worker. While the Web Workers are fetching, processing, and calculating their data, the main JS could be setting up menus, event listeners, initializing date pickers and custom UI elements, etc. And when each Web Worker is done with its process, it can report back to the main JS with its resulting data to be used to create its respective chart.

While Web Workers cannot directly interact with the DOM, your main JS code can do that based on the messages you receive back from a Web Worker. And as they are completely separate threads, Web Worker code must exist in a separate file and does not have access to your main JS. Workers can also spawn subworkers, to create additional background threads.

Support for Web Workers is quite good, with only IE < 10 and Android < 4.4 deserving any real consideration.

Web Worker resources:

WebSockets

HTML5 Rocks has a nice introduction to WebSockets (aka Sockets). From that article, the best one-line definition I found was:

There is an [sic] persistent connection between the client and the server and both parties can start sending data at any time.

WebSockets are pretty perfect for any web app that needs to communicate frequently with a server, and could benefit from the server being able to communicate directly with the client.

For example, a chat app could create a WebSocket connection so that as each person types, their message is pushed to the server and the server can then send that message directly to the other person(s) in that chat. The previous methods for doing this would be using setTimeout, setInterval and Ajax requests. But these approaches created intensive loops that have to keep asking the server: “Do you have anything yet?” No. “Do you have anything yet?” No. “Do you have anything yet?” No…

So, with WebSockets we finally can directly affect the DOM and, as they are part of the main thread, WebSockets do have access to your main JS.

Support for WebSockets is quite good, with only IE < 10 and Android < 4.4 deserving any real consideration.

WebSockets resources:

Summation

So, while WebSockets and Service Workers kind of overlap, both being used for client-server communications, WebSockets would be used more for continuous communication so both the client and the server can send messages to each other without having to create new connections, and Service Workers would be used more for one-off client-server communications like syncing an app and the database after the app was offline for some time, like a burst that can then be dropped when the sync is completed.

And Web Workers are something completely different, allowing processor-intensive functions to run in a separate, background thread, while allowing the main JS to run and the UI to setup and operate more smoothly while those intensive functions are still running in the background.

Well, I hope this quick look at Service Workers, Web Workers and WebSockets helped clear up the similarities, differences, and purposes of these great new web technologies for you, as much as it did for me! As always, please feel free to drop any questions/thoughts into the comments below; discussion is always fun. :-)

Happy coding,
Atg

Today’s Readings

shares how to automatically detect and fix JS code style violations. Handy, and so easy!

An interesting warning against using || to set default values, specifically addressing bugs when values passed into functions are truthy or falsey…

shows you how to combine WordPress and Sass to organise your code and streamline your workflow. Thanks, Jason! :-)

walks total React newbies like me through an über basic intro, explaining states and how they work within React. As Stu says, if you know anything about React or “any of the frontend frameworks like Backbone/Ember/Angular, this tutorial is NOT for you.”

In ‘s Fun with the Web Animations API presentation, he gives us a taste of the great things to come!

walks us through her process for creating responsive, art-directed, embedded SVGs.

The CSSConf Australia presentation from start innocently enough by discussing the basics of CSS animation, but soon gets into the Earth’s gravitational pull, how Bézier curves work, and more… So, prepare yourself… :-)

On average, how many @media queries do you use on a project? If you’re like me, the answer is exactly the number needed, no more, nor less… ;-) warns that we can overdo things

Until the CSS Speech Module is supported in browsers, suggest this option of Using the Web Speech API to simulate CSS Speech support.

‘s first installment of 12 Little-known CSS Facts was so much fun, he decided to provide us with another 12! Thanks, Lou!

says us that, when it comes to explaining the importance of performance, like so many other things in life, it is often easier to show, than to tell

And finally, someone call the authorities, I think I just saw RD-D2 fly past my window… Nope, sorry, it was Snoopy

Happy reading,
Atg

Today’s Readings

ZOMG!!! A Bluetooth-connected Star Trek communicator… Too bad (or maybe Thank God!) the pre-order link in the article is busted, and the company’s own website is rather junky… I have been saying since the very first flip-phone came out, that someone needs to make one that makes the communicator sound when it opens, but this is SO much better!

points out a common pattern that can be found on the web: breaking the web with shitty code.

And speaking of shitty code, ever tried to copy and paste something from a website (not code, but the actual rendered content), and have some shitty code blocking that via JS? Yeah, it sucks. And it’s stupid, because it’s so easy to get around. Well it just got even easier, because present us with a very simple bookmarklet to add to our browsers to break that behavior! :-)

As a follow-up to his Limitations on Styling Visited Links article, offers a couple more options for styling visited links, including using inline SVG and Unicode characters.

Here are a couple Interactions for Draggable Elements. While I am inspired by the tech, I find the interactions completely unintuitive, and could not suggest using either in a production site. But again, nice animation, and good inspiration for a better interface.

Hey nature-lovers, this free (and ad-free!) app helps you identify the plants and animals around you! So go get your nature on!

Basket.js: A simple (proof-of-concept) script loader that caches scripts with localStorage

Interesting concept!

The text from ‘s 2015 CSS Summit presentation Designing with Progressive Enhancement. Using “design” in the broader scope, as in “planning”. Long read, but well worth it, some really great bits in there; the article links to the slides as well.

The Web’s Cruft Problem. Certainly not news to anyone, and a hard battle to fight. Not technologically, as developers we can pull bullshit out, push the remains together to reduce requests, minify those requests, then distribute it all around the world via CDNs for nice, fast, reliable content delivery. The hard part is that our bosses always want to make money, so we can all get paid. The examples of “solving” this problem (Flipboard and Facebook’s Instant Articles) aren’t doing it for free, but businesses should realize that the faster people can get things, the more they will consume, and the more they will return, and the more they will consume.·. And they won’t have to pay Flipboard or split ad revenue with Facebook…

YWebCA. Fan-freaking-tastic!!

Atomic OOBEMITSCSS. Scary, but yeah. That’s it. As it should be. Love it.

Pretty sweet CSS-powered animated Ajax page transitions.

Seven Surprising JavaScript ‘Features’. Although several of these are ES6, and I am trying hard to ignore that for now, some are older, and all are still interesting.

Slick technique from to merge one JS array into another, without creating a new array in the process.

And finally, with all the hub-bub focusing on New Horizon’s fly-by of the (non-)planet Pluto, let’s talk about how well you know the other (actual) planets

Happy reading,
Atg

Today’s Readings

There are so many “recent” web technologies that I have been ignoring because I feel like they’re just not ready for prime time yet. Web Workers has been one. Until I read this How Fast are Web Workers article, which impressed me, and prompted me to check-out browser support, which looks pretty darned good!

A recent What a Tool! newsletter pointed out some great HTML API properties, and linked to the entire collection on MDN; I did not know many of these existed!

Wow, takes a monster DevTools deep-dive into the performance (or lack thereof) of Reddit’s mobile website. 1.1MB of minified JS… Ouch…

Hack Physics and JavaScript (part 1). Good, clean, JS physics fun!! Can’t wait for part 2!!

Maybe not quite as exciting an example of physics, this nevertheless is a fine example of a bounce.

ßo we’re all slowly crawling out of the last century and making all of our sites responsive, right? Okay, great. Now let’s also make all of our sites multilingual with these 13 tips for making responsive web design multi-lingual… :-)

Got WordPress? Go a login page that looks like every other WordPress site’s login?? Yeah, me too. Well, Tuts+ is here to help you create a custom login page, including custom branding.

Speaking of WordPress, and specifically the admin-side, how is your page load speed? I know for me, things like saving or updating a post can be pretty darned slow. So here is a little debug task to try to find (and resolve) any performance bottlenecks!

Safari is the new IE certainly made the rounds last week. So much so that it got its own website and petition! Dang.

The Art of Command Line: Master the command line, in one page. Seriously thorough endeavor. Too bad it is (mostly) only about Linux, as I’m only ever in Mac OS or Windows… :-/

So I will simply have to check-out this Smashing Magazine article Become A Command-Line Power User With Oh-My-ZSH And Z! :-)

Code reviews are smart business. Not only do they ensure that you are about to launch the most efficient way to do something, but they also ensure that all internal standards have been met, that team members understand how something new works, and they are a great way for team members to knowledge-share! But it’s also incredibly rare for teams to be allotted time to perform this task. Time, money, etc. But even when it is done, I have never seen anyone do it with CSS! Which is crazy, because that mess can become a far worse pile of spaghetti in no time at all! Anyhow, here is an example of what a CSS code review might look like. Enticing…

Some fine pointers for designers on how to better work with developers. I would also like to see a similar, but reverse-oriented article, if anyone knows of a good one.

And finally, [w]atch the Mars Opportunity rover run an 11-year marathon in this time-lapse. Yeah, that’s driving… on Mars… :-)

Happy reading,
Atg