Toby Rogers

Toby Rogers

1559198017

An Introduction to Web Workers for Beginners

Learn how to use web workers in JavaScript to create parallel programming and perform multiple operations simultaneously rather than interleaving them.

Web workers enable developers to benefit from parallel programming in JavaScript. Parallel programming lets us run different computations at the same time. Let’s see how we benefit from doing tasks in parallel as humans to help us understand the value of web workers.

Let’s imagine that each one of us runs a tech blog. We work by ourselves and are responsible for coding a demo app, writing about the app development process, and creating assets for the post (like diagrams, images, or logos). That’s a heavy task pipeline to handle by ourselves. Coding the app and writing the content are interconnected since the experience of writing the code motivates writing the content. However, creating assets is something that we could delegate to someone else.

Let’s say that we have a group of friends that are talented designers. They agree to create the assets for us. All that they ask is for us to message them a description or sketch of the asset and they will reply back with a cool professional version of it when they are done. Now, we only need to focus on coding, writing, and integrating the assets of the designers once they message us.

This will give us a huge productivity boost. Initially, we were being blocked from coding and writing whenever we had to design assets. The completion of a blog post would have taken much longer if we were to work alone than if we were to delegate one task to a designer friend.

The design team handles the task asynchronously on their own pipeline. The design team acts exactly how a web worker acts in JavaScript applications. JavaScript is a single-threaded language. As such, running expensive logic in the main thread can block it and make our JavaScript application seem slow or unresponsive. Using web workers, we can create a separate thread to run any logic without interrupting the main thread.

[“Web workers in JavaScript allows us to create parallel programming to perform multiple operations simultaneously rather than interleaving them.”> [“Web workers in JavaScript allows us to create parallel programming to perform multiple operations simultaneously rather than interleaving them.”
Let’s explore what we need to know to make use of web workers in JavaScript and what benefits it brings to a web application.
[“Web workers in JavaScript allows us to create parallel programming to perform multiple operations simultaneously rather than interleaving them.”> [“Web workers in JavaScript allows us to create parallel programming to perform multiple operations simultaneously rather than interleaving them.”> [“Web workers in JavaScript allows us to create parallel programming to perform multiple operations simultaneously rather than interleaving them.”> [“Web workers in JavaScript allows us to create parallel programming to perform multiple operations simultaneously rather than interleaving them.”## Why use JavaScript Web Workers?

Let’s expand a bit more on what Jason Miller explained in his tweets.

In JavaScript, we can create parallel programming to perform multiple operations simultaneously using web workers. Web workers let us create background threads that are separate from the main execution thread, where we usually run our user interface logic. The core advantage of this workload separation is that we can run expensive operations within an isolated thread without interrupting or affecting the responsiveness and usability of the main thread. When the background thread completes its task it seamlessly notifies the main thread about the results through an event that is managed through regular JavaScript event handling.

[“Web workers in JavaScript allows us to create parallel programming to perform multiple operations simultaneously rather than interleaving them.”> [“Web workers in JavaScript allows us to create parallel programming to perform multiple operations simultaneously rather than interleaving them.”#### Tweet This
[“Web workers in JavaScript allows us to create parallel programming to perform multiple operations simultaneously rather than interleaving them.”> [“Web workers in JavaScript allows us to create parallel programming to perform multiple operations simultaneously rather than interleaving them.”
Web workers effectively enable a form of multi-threading in JavaScript with some restrictions such as not being able to access the DOM and not having access to the web worker’s parent page (the page that created it). With that in mind, let’s learn next how we can create web workers.

Setting Up a Development Environment

Getting hands-on with web workers will help us understand them better! For the purpose of this blog post, we’ll be running the sample code within a CodeSandbox project. It’s easy to bootstrap and run a vanilla JavaScript project there. Please, follow these steps:

<html>

<head>
    <title>Parcel Sandbox</title>
    <meta charset="UTF-8" />
</head>

<body>
    <div id="app"></div>

    <script src="src/main.js"></script>

</body>

</html>

We’ll soon learn why we are creating these files. CodeSandbox uses ParcelJS to bundle the JavaScript application easily.

[“Web workers in JavaScript allows us to create parallel programming to perform multiple operations simultaneously rather than interleaving them.”## Creating Web Workers

To create a web worker, we use the [Worker()](https://developer.mozilla.org/en-US/docs/Web/API/Worker/Worker "Worker()") constructor from the Web Workers API. The Worker() constructor has the following signature:

Worker(aURL, options);


aURL is a string that represents the URL of the script that we want the worker to execute.

options is an object to customize the Worker instance. The allowed options are type, credentials, and name. We don’t need to configure them for the scope of this post.

In practice, we instantiate a web worker in the main thread. The main thread could be represented by a JavaScript file, for example, main.js, that is the entry point to the application. The web worker thread could be represented by another file, for example, worker.js. main.js then creates a new Worker using the worker.js file. Let’s see this in action.

Let’s open src/main.js in our project and populate it with the following code:

// src/main.js

const worker = new Worker("../src/worker.js");


In the code above, worker becomes a Worker instance that will execute the script on worker.js.

[“Web workers in JavaScript allows us to create parallel programming to perform multiple operations simultaneously rather than interleaving them.”
That’s it for the creation of a web worker! We effectively now have two threads available in our application: main and worker. Next, we’ll learn how to communicate between threads.

Sending Messages To and From a Web Worker

In the introduction, we discussed how the internal collaboration between our Content and Design teams at Auth0 resemble the interaction between threads using web workers in JavaScript. In our case, a Content Engineer represents the main thread and the Designer represents the worker thread. How would the main thread ping the worker thread and vice versa? We do that through the [postMessage()](https://developer.mozilla.org/en-US/docs/Web/API/Worker/postMessage "postMessage()") method and the [onmessage](https://developer.mozilla.org/en-US/docs/Web/API/Worker/onmessage "onmessage") event handler from the Web Workers API.

Let’s use the classic Marco Polo game to see this communication in action. In this game, one player shouts “Marco!” and the other player must reply “Polo!”. Within our context we want to do the following:

  1. main.js and worker.js are on standby listening for any message between each other.
  2. main.js sends a message to worker.js: "Marco!".
  3. worker.js gets the message from main.js and replies: "Polo!".
  4. Step 2 and Step 3 are repeated infinitely.

Step 1: Listen for Messages

The Worker.onmessage event handler let us listen for messages between the threads. The signature of this Worker event handler property is as follows:

myWorker.onmessage = e => {
  // Event handler logic
};


The function assigned to onmessage is called when a message event occurs.

To set this up in main.js, we use the Worker instance we created:

// src/main.js

const worker = new Worker("../src/worker.js");

worker.onmessage = e => {};


To set this up in the web worker thread represented by worker.js, we use the onmessage property directly:

// src/worker.js

onmessage = e => {};


How do we access the message data that is being sent? The message payload can be accessed from the message event’s data property.

Let’s update our code as follows:

// src/main.js

const worker = new Worker("../src/worker.js");

worker.onmessage = e => {
  const message = e.data;
  console.log(`[From Worker]: ${message}`);
};

// src/worker.js

onmessage = e => {
  const message = e.data;
  console.log(`[From Main]: ${message}`);
};


Let’s save our work for each file. On CodeSandbox, we can use CMD + S or CTRL + S to save each file.

We got our threads listening for messages between each other. Next, let’s learn how to send messages.

Step 2: Send a Message from Main Thread to Worker Thread

To send messages, we rely on the Worker.postMessage() method:

worker.postMessage(message);


The postMessage() takes a single parameter representing the data that we want to send. This data may be any value or JavaScript object handled by the structured clone algorithm. As noted by MDN, the structured clone algorithm is an algorithm defined by the HTML5 specification for copying complex JavaScript objects. Why do we need to rely on this algorithm? Data transferred through web workers is passed as a copy, not as a reference.

With an understanding of how postMessage() work, let’s use this method to send a message from the main thread to the worker thread:

// src/main.js

const worker = new Worker("../src/worker.js");

worker.onmessage = e => {
  const message = e.data;
  console.log(`[From Worker]: ${message}`);
};

worker.postMessage("Marco!");


Let’s save our work and open the application preview on its own tab. This can be done by clicking on the Open In New Window button present in the navigation bar of the embedded browser:

In the new preview browser tab, let’s open the browser developer console and refresh the page. We should see the following output:

// [From Main]: Marco!


This output in the console confirms that our web worker is listening and reacting to the message event sent from main.js. Now, we need to reverse the communication. We need to send a message reply from worker.js to main.js.

Step 3: Send a Message from Worker Thread to Main Thread

This will be quick. We need to use the postMessage() method in the onmessage event handler in worker.js:

// src/worker.js

onmessage = e => {
  const message = e.data;
  console.log(`[From Main]: ${message}`);

  postMessage("Polo!");
};


Let’s save our work and refresh the preview browser tab. In the console, we should now see the following output:

// [From Main]: Marco!
// [From Worker]: Polo!


We have achieved bi-directional communication between threads, but the communication is short-lived. Let’s make this multi-threaded Marco Polo game run infinitely.

Step 4: Send Messages Between Main and Worker Infinitely

We are going to keep the communication between threads going endlessly. To better pace the back and forth, we are going to rely on [setTimeout()](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout "setTimeout()") to delay messaging by 3 seconds.

To start, when main.js gets a message from worker.js, it replies back after 3 seconds:

// src/main.js

const worker = new Worker("../src/worker.js");

worker.onmessage = e => {
  const message = e.data;
  console.log(`[From Worker]: ${message}`);

  const reply = setTimeout(() => worker.postMessage("Marco!"), 3000);
};

worker.postMessage("Marco!");


Next, when worker.js gets a message from main.js it also replies back after 3 seconds:

// src/worker.js

onmessage = e => {
  const message = e.data;
  console.log(`[From Main]: ${message}`);

  const reply = setTimeout(() => postMessage("Polo!"), 3000);
};


The 3 seconds delay creates an eye-friendly pause to be able to see the communication calmly in the developer console. What makes this work infinitely is that every handled message event executes a postMessage() response. Before, the worker.onmessage in main.js did not have a reply within its body.

Let’s save our work and head back to the browser preview. Let’s refresh the page. After a few seconds, we should see the following output:

// [From Main]: Marco!
// [From Worker]: Polo!
// [From Main]: Marco!
// [From Worker]: Polo!


Your browser doesn’t support HTML5 video. Here is a instead.

This will go on forever until we close the browser tab running the preview of our application. But, we could also terminate the web worker manually. Let’s see how we can do that next.

Terminating a Web Worker

We can terminate web workers from the main thread immediately or from the worker thread.

From the main thread, we can terminate a web worker by calling the [terminate()](https://developer.mozilla.org/en-US/docs/Web/API/Worker "terminate()") method of the Web Workers API:

worker.terminate();


After terminate() is issued, the web worker is destroyed immediately without any chance of completing any ongoing or pending operations. The web worker is also given no time to clean up. Thus, terminating a web worker abruptly may lead to memory leaks.

We can also terminate a web worker from the worker thread using its own [close](https://developer.mozilla.org/en-US/docs/Web/API/DedicatedWorkerGlobalScope/close "close") method:

close();


Upon calling close(), any queued tasks present in the event loop are discarded and the web worker scope is closed.

Checking the documentation for close() may be confusing at first because there is a version of the [close()](https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope "close()") method that has been deprecated. The deprecated version belongs to the WorkerGlobalScope interface. In reality, there are two types of web workers that we can create: dedicated and shared web workers. Each web worker type has its own interface, [DedicatedWorkerGlobalScope](https://developer.mozilla.org/en-US/docs/Web/API/DedicatedWorkerGlobalScope "DedicatedWorkerGlobalScope") and [SharedWorkerGlobalScope](https://developer.mozilla.org/en-US/docs/Web/API/SharedWorkerGlobalScope/close "SharedWorkerGlobalScope") respectively. For the scope of this introduction, we’ve used a dedicated web worker under the hood. The difference between these two types of web workers and how and where to use them will be addressed in a future post along with best practices on terminating workers!

Recap

We’ve learned the basics of how to create a web worker. We learned how to effectively send messages between two threads and how to react to those messages. We briefly touched on the subject of terminating web workers. This last task is to be handled with care and deserves a more detailed explanation. Badly terminated web workers may lead to memory leaks in the application.

[“Web workers in JavaScript allows us to create parallel programming to perform multiple operations simultaneously rather than interleaving them.”
What’s left to learn? A lot! Web workers have been around for a long time and they are great at executing expensive logic. This logic will be much more complex than what we’ve done in this blog post. We’d need to learn topics like handling errors, spawning subworkers, using external libraries, and monitoring web workers using developer tools.

Please let me know in the comments how you liked this introduction to web workers and what else you’d like to learn about this handy technology that lets us perform parallel programming in JavaScript.

#javascript #web-development

What is GEEK

Buddha Community

An Introduction to Web Workers for Beginners
Ashish parmar

Ashish parmar

1627043546

Evolution in Web Design: A Case Study of 25 Years - Prismetric

The term web design simply encompasses a design process related to the front-end design of website that includes writing mark-up. Creative web design has a considerable impact on your perceived business credibility and quality. It taps onto the broader scopes of web development services.

Web designing is identified as a critical factor for the success of websites and eCommerce. The internet has completely changed the way businesses and brands operate. Web design and web development go hand-in-hand and the need for a professional web design and development company, offering a blend of creative designs and user-centric elements at an affordable rate, is growing at a significant rate.

In this blog, we have focused on the different areas of designing a website that covers all the trends, tools, and techniques coming up with time.

Web design
In 2020 itself, the number of smartphone users across the globe stands at 6.95 billion, with experts suggesting a high rise of 17.75 billion by 2024. On the other hand, the percentage of Gen Z web and internet users worldwide is up to 98%. This is not just a huge market but a ginormous one to boost your business and grow your presence online.

Web Design History
At a huge particle physics laboratory, CERN in Switzerland, the son of computer scientist Barner Lee published the first-ever website on August 6, 1991. He is not only the first web designer but also the creator of HTML (HyperText Markup Language). The worldwide web persisted and after two years, the world’s first search engine was born. This was just the beginning.

Evolution of Web Design over the years
With the release of the Internet web browser and Windows 95 in 1995, most trading companies at that time saw innumerable possibilities of instant worldwide information and public sharing of websites to increase their sales. This led to the prospect of eCommerce and worldwide group communications.

The next few years saw a soaring launch of the now-so-famous websites such as Yahoo, Amazon, eBay, Google, and substantially more. In 2004, by the time Facebook was launched, there were more than 50 million websites online.

Then came the era of Google, the ruler of all search engines introducing us to search engine optimization (SEO) and businesses sought their ways to improve their ranks. The world turned more towards mobile web experiences and responsive mobile-friendly web designs became requisite.

Let’s take a deep look at the evolution of illustrious brands to have a profound understanding of web design.

Here is a retrospection of a few widely acclaimed brands over the years.

Netflix
From a simple idea of renting DVDs online to a multi-billion-dollar business, saying that Netflix has come a long way is an understatement. A company that has sent shockwaves across Hollywood in the form of content delivery. Abundantly, Netflix (NFLX) is responsible for the rise in streaming services across 190 countries and meaningful changes in the entertainment industry.

1997-2000

The idea of Netflix was born when Reed Hastings and Marc Randolph decided to rent DVDs by mail. With 925 titles and a pay-per-rental model, Netflix.com debuts the first DVD rental and sales site with all novel features. It offered unlimited rentals without due dates or monthly rental limitations with a personalized movie recommendation system.

Netflix 1997-2000

2001-2005

Announcing its initial public offering (IPO) under the NASDAQ ticker NFLX, Netflix reached over 1 million subscribers in the United States by introducing a profile feature in their influential website design along with a free trial allowing members to create lists and rate their favorite movies. The user experience was quite engaging with the categorization of content, recommendations based on history, search engine, and a queue of movies to watch.

Netflix 2001-2005 -2003

2006-2010

They then unleashed streaming and partnering with electronic brands such as blu-ray, Xbox, and set-top boxes so that users can watch series and films straight away. Later in 2010, they also launched their sophisticated website on mobile devices with its iconic red and black themed background.

Netflix 2006-2010 -2007

2011-2015

In 2013, an eye-tracking test revealed that the users didn’t focus on the details of the movie or show in the existing interface and were perplexed with the flow of information. Hence, the professional web designers simply shifted the text from the right side to the top of the screen. With Daredevil, an audio description feature was also launched for the visually impaired ones.

Netflix 2011-2015

2016-2020

These years, Netflix came with a plethora of new features for their modern website design such as AutoPay, snippets of trailers, recommendations categorized by genre, percentage based on user experience, upcoming shows, top 10 lists, etc. These web application features yielded better results in visual hierarchy and flow of information across the website.

Netflix 2016-2020

2021

With a sleek logo in their iconic red N, timeless black background with a ‘Watch anywhere, Cancel anytime’ the color, the combination, the statement, and the leading ott platform for top video streaming service Netflix has overgrown into a revolutionary lifestyle of Netflix and Chill.

Netflix 2021

Contunue to read: Evolution in Web Design: A Case Study of 25 Years

#web #web-design #web-design-development #web-design-case-study #web-design-history #web-development

Kabanda  Nat

Kabanda Nat

1624264277

How Web Works - Web Application Architecture for Beginners

Do you know that there is a difference between websites and web applications? ( you might have thought that both are the same). The web application is a program that runs on a browser and it has mainly three formal characteristics.

  • Addresses a particular problem, even if it’s simply finding some information
  • As interactive as a desktop application
  • Works with Content Management System.
    If we talk about the website then traditionally it’s just a combination of static pages. A website becomes a web application when it consists of both static and dynamic pages (yes!! it’s true that all modern websites are the example of web applications.
    Web application architecture is a mechanism that gives us a clarification that how the connection is established between the client and the server. It determines how the components in an application communicate with each other.

#web application #architecture #beginners #web works #web dev

prashant patil

1598286700

whatsapp web-w app web-webs whatsapp »

Through whatsapp web you can easily run whatsapp on your android pc on your android mobile. Just like whatsapp mobile is for android device, whatsapp web is for windows device. Whatsapp web is quite popular which has quite cool features.

whatsapp web

how to use whatsapp web desktop
Whatsapp web is very easy to use. Simply you have to search web.whatsapp.com in your google chrome and click on first result which is the official website of whatsapp web.

As soon as you click, an interface will open in front of you, on which you will see a barcode. Follow the steps given below to use whatsapp web on your desktop

web.whatsapp.com

open your whatsapp on your mobile
You will see 3dots on the right side top inside whatsapp, you have to click
The 3rd option is whatsapp web, you have to click it
Now you have to capture the barcode you see on your desktop through your phone.
Now you can use whatsapp of your android mobile in your desktop
webs whatsapp

note: You can see whatsapp of anyone’s mobile by pointing to the barcode of your desktop. You can also call it whatsapp hack.

Remember that after using whatsapp web, logout it from your desktop. To logout follow the steps given below.

w app web

open your whatsapp on your mobile
You will see 3dots on the right side top inside whatsapp, you have to click
The 3rd option is whatsapp web, you have to click it
You will see the symbol for logout, you have to logout by clicking it.

read more

#whatsapp #whatappweb #https://web.whatsapp.com/ #wsp web #web.whatsapp web #web whatsapp

Ananya Gupta

1613386017

Key Points For Joining The Best Web Designing For Better Career Option

The scope of the web designer is increasing day by day, because of high demanding job forms an important part of our society. Web Designing is that the creation and planning of internet sites. it’s a process of developing different sites.

To be an honest web designer you ought to have an entire knowledge of CSS and HTML. These are the important prerequisite for designing an internet site. In today’s world of competition to be amongst at the highest one needs media. Websites are playing a key role in today’s life. Whether in online web desiging course mention shopping or engineering everything is formed online.

These are some of the main benefits which a standard person has made with the utilization of internet sites. many roles are available for web designers than before. Many big companies demand experienced and quality web designers.

Web designing is the creative and innovative part of web development during which the designer is especially concerned with how our website looks. CSS is the heart of the web designing part.

The scope of web designing is increasing day by day. In today’s web and internet world, people want a creative website once they want to access it. Top company web development of India hands over 8-10 lac per annum for an experienced web designer. So it’s a really good field for creating websites.

Web designers have the work of designing whole websites which forms the primary step of web development. After web designing remaining work will start. In today’s growing scenario there are many job opportunities for fresher and experienced candidates.

Web designing is a crucial course that features a lot of scope within the present and also in the future scenario. There are two ways to travel through this course. If you’re curious about taking over a full-time web designer course then we will make a career in media or as advertising agents.

If one is curious about Engineering or in Commerce course but getting to develop the skill in web designing, then you’ll prefer the part-time short course in web designing.

When it comes to selecting a training institute, you will find them in every corner. CETPA Infotech is a reputed training institution and provides training that is industry oriented, updated, innovative and summer training has become a pioneer during this online designing field.

#web designing training in noida #web designing training in delhi #web designing online training #web designing online course #web designing course #web designing training

Sunny Joshi

1626433760

Best Web Development Institute in Delhi - Online Course

If you want to pursue a career in Web Development, then you must opt for a Web Development course in Delhi. The Best Web Development Institute in Delhi is offered by Web Development colleges or institutions. They are designed to give you the necessary training to start a Web Development company or a web design business. These courses are generally provided by Techstack and other institutes in Delhi like APTRON, ADMEC, Next G Education etc. contact them and get the best online training in India. These institutes offer the basic courses with advanced level of courses.

Their courses help you learn Web Development and web marketing. The Best Web Development Institute in Delhi will enable you to understand the basic requirements of web design and Web Development. You can also enhance your web design skills through these Web Development courses in Delhi. The Web Development training in Delhi from an experienced Web Development institute in India will teach you Web Development principles and methods through their live projects. This course in Delhi from an institute of good repute has a host of practical, theoretical and educational lessons which can be followed closely. These Web Development training institutes in Delhi can be followed up with classroom learning.

Best Web Development Institute in Delhi:

The institute, which you select for training in Delhi can decide the schedule of classes. Some Web Designing institutes provide you with the opportunity of choosing a particular institute for online training also. In this case, you would be able to find Web Development courses in Delhi conducted by that institute. The course work of these institutes is generally taught in a classroom setting. Most of these institutes conduct both classroom sessions and web-based courses.

You can take Web Development training in Delhi from an institute which offers you real world-class online training. The Techstack Academy conducts its Web Development training in a traditional manner. Students can create their own applications using the modern lab environment provided at the best institute. Many institutes conduct their web-based online course in a modern lab setup. They have a number of modern labs where students can interact with their teachers and fellow students of the same institute. This interaction helps the students identify and grasp concepts in an easy manner.

In the Web Development training in Delhi from an institute of good repute, students can choose between Web Development with live projects, web design and Web Development with prototypes with manual coding. The students can choose the best course for them depending on their goals and preferences.

Also Read: Web Development Course in Delhi (#1 Best Training Institute)

With regard to Web Development training in Delhi, the first step that the students have to take is to register themselves at the Best Web Development Institute in Delhi of their choice. Once they are registered, they can choose the course of their choice. Some of these training centers offer intensive training while some do not offer any specialised training and hence students can easily find an online training institute in Delhi NCR also that suits their needs.

In order to get a web designing course in Delhi, one has to follow certain rules. First of all, the students need to contact the Web Development training centre in Delhi and register themselves for the course. The Best Web Development Institute in Delhi may conduct an interview process or conduct a web-course interview. The institute needs to understand the skills that the student possesses. Students can look forward to a bright career in web designing courses in Delhi as they can secure a number of jobs after completing their courses.

#web designing course in delhi #web development institute in delhi #web development training in delhi #web development course #web development institute #best web development institute in delhi