DEV Community

Tobias Uhlig
Tobias Uhlig

Posted on

Chrome v80 release: JS module support for workers

Google just released Chrome version 80 on Tuesday, February 4, 2020. I personally waited for this specific release for over one year and it feels like the most important major release in a very long time.

https://www.chromestatus.com/features/schedule

What is a Javascript module?

As soon as you are using the ES6+ class system, you will most likely automatically work with JS modules:

Alt Text

If you stick to the “1 class per file” design pattern, you will most likely want to import the base class which you extend. You will also most likely want to export the new class at the end of your file. As soon as you are using an import or export statement, your file is already considered to be a JS module.

Can JS modules run directly inside a browser?

Inside the main thread, this is already possible in Chrome, Firefox & Safari for a long time. Using JS modules inside a web worker was already possible in Chrome for quite some time as well, but hidden behind an experimental flag. Now with Chrome v80, it is finally possible out of the box.

Side note: this widens the gap between Chrome & other browsers by a long shot. Sadly the FF & Safari dev teams have related tickets open for several years, without any priority.

How to create a worker from a JS module?

It is up to you if you want to name your js module files .mjs or just .js, adding type: ‘module’ is the key to do it.

Alt Text

What is the advantage to use JS modules directly inside the browser?

You can create well structured apps and run them inside the browser without the need for any JS related build processes. Meaning: you can change the source code and just reload the browser page, without the need for webkit watching the file-changes & hot module replacements.

Is there already a web workers driven JS UI framework out there?

Yes, neo.mjs got released to the public on November 23rd, 2019.

Repository:

https://github.com/neomjs/neo

Online Examples:

https://neomjs.github.io/pages/

What is coming next?

If you did look close at the release schedule, you might have noticed that Chrome v81 is scheduled for March 17th. This version will include JS module support for shared workers. This is the key for crafting multi browser window apps (e.g. apps which can run on multiple screens).

Best regards & happy coding,
Tobias

Top comments (1)

Collapse
 
louis profile image
Louis Augry

Also with v80, you can do optional chaining !

// Less error-prone, but harder to read.
let nameLength;
if (db && db.user && db.user.name)
  nameLength = db.user.name.length;

// Still checks for errors and is much more readable.
const nameLength = db?.user?.name?.length;