In the context of web development, “defer” and “deferred” are terms associated with optimizing the loading and execution of JavaScript code.
- JS Defer:
- When the
defer
attribute is added to a script tag in HTML, it signals the browser to continue parsing the HTML document while simultaneously downloading the external JavaScript file in the background. The script is then executed in order after the HTML parsing is complete. This can lead to improved page loading performance, especially for scripts that are not critical for the initial page render.
- JS Deferred:
- “Deferred” is a term often used in the context of promises in JavaScript. A deferred object represents a value that may not be available yet but will be resolved or rejected at some point in the future. It provides a way to work with asynchronous operations in a more organized and readable manner. Promises in JavaScript use the concept of deferred to handle asynchronous code flow and manage the success or failure of an operation. read more