Lenix

A few recommended practices for writing good JavaScript asynchronous code

Today, I will recommend a few recommended practices for writing JavaScript asynchronous code. Each scenario has a corresponding eslint rule, and you can choose to configure it. no-async-promise-executor Passing an async function to the constructor of new Promise is not recommended. // ❌ new Promise(async (resolve, reject) => {}); // ✅ new Promise((resolve, reject) =>

A few recommended practices for writing good JavaScript asynchronous code Read More »

Lazy loading of non-critical CSS

CSS files are render-blocking resources : they must be loaded and processed before the browser can render the page. Web pages that contain unnecessarily large styles take longer to render. In this guide, you’ll learn how to lazy load non-critical CSS with the goal of optimizing the critical rendering path and improving First Contentful Paint

Lazy loading of non-critical CSS Read More »

Detailed explanation of http CORS options request (preflight request)

1. Introduction to CORS for Cross-Origin Resource Sharing The entire CORS communication process is automatically completed by the browser and does not require user participation. The key to implementing CORS communication is the server. Cross-origin communication is possible as long as the server implements the CORS interface. The OPTIONS request is a preflight request ,

Detailed explanation of http CORS options request (preflight request) Read More »

Inventory those black technologies used in low-latency network architecture!

Hello everyone, I’m Fei Ge! Recently, I briefly studied the low-latency network architecture and shared it with you today. When it comes to an excellent low-latency network architecture, the first thing that comes to mind is the Internet giants, such as Tencent Alibaba Bytes. They always feel that the big companies must do the best.

Inventory those black technologies used in low-latency network architecture! Read More »

postMessage – cross domain messaging

The window.postMessage() method allows scripts from one document to pass text messages to scripts in another document, regardless of whether they are cross-domain or not. Scripts in one document still cannot call methods and read properties in other documents, but they can communicate securely using this messaging technique. This technique is called “Cross Document Messaging”,

postMessage – cross domain messaging Read More »

js generates random numbers

js generates random numbers usually using the Math.random() function of javascript Several commonly used methods: Math.random() means: the result is between 0-1 (including 0, excluding 1); Math.floor(Math.random()*10+1) indicates that the result is a random number between 1-10 Math.floor(Math.random()*24) means the result is a random number between 0-23 1.Math.random(); returns a random number between 0-1, may

js generates random numbers Read More »

Two ways to get custom attributes in js

js to get two methods of custom attributes Four ways to get properties First get an element: var elem = document.getElementById(‘elem’); 1 1. Point (can not get custom attributes): 2. [] can also get attributes, which is beneficial for parameter transfer operations. elem.style[‘background’] = ‘yellow’ 1 3. getAttribute(): The early method of obtaining custom attributes.

Two ways to get custom attributes in js Read More »