https://github.com/lorddashme/learning-js-web-workers
A simple example to test the Web Workers separation to the main browser window thread.
https://github.com/lorddashme/learning-js-web-workers
javascript js mozilla web-workers webworker-demo workers
Last synced: 8 months ago
JSON representation
A simple example to test the Web Workers separation to the main browser window thread.
- Host: GitHub
- URL: https://github.com/lorddashme/learning-js-web-workers
- Owner: LordDashMe
- License: mit
- Created: 2019-08-16T03:19:55.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-01-06T01:58:08.000Z (almost 6 years ago)
- Last Synced: 2025-01-16T00:57:30.976Z (10 months ago)
- Topics: javascript, js, mozilla, web-workers, webworker-demo, workers
- Language: HTML
- Size: 9.77 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Learning JS Web Workers
A simple example to test the Web Workers separation to the main browser window thread.
## Usage
- The JS Web Workers requires to run with a domain or in a http-server, thus this will not work in a ```file://```.
- Open the ```index.html``` file in your preferred browser and you can now check how JS Web Workers separated from the main thread by click the buttons.
- You might wonder why the UI doesn't change and the worker seems like blocked by the main thread when you start the block thread and prompting an ```alert()```.
- I added a ```console.log()``` inside the ```worker.js```, this can be use to verify the process of the worker is actually done in the background and not blocked by the main thread.
- To check this you need to open your browser developer console tab.
### Restriction
- Web Workers can't access DOM elements from the web page.
- Web Workers can't access global variables and JavaScript functions from the web page.
- Web Workers can't call alert() or confirm() functions.
- Objects such as window, document and parent can't be accessed inside the web worker.
## Reference
- [Developer Mozilla](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers)
## License
This package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).