Home >Web Front-end >JS Tutorial >Comparison of several ways for the front end to obtain session information

Comparison of several ways for the front end to obtain session information

巴扎黑
巴扎黑Original
2017-07-18 18:24:495986browse

During development, page js often encounters places where the currently logged in user information (menu permissions, basic user information, configuration information) is required. Generally speaking, we may not care too much about how to obtain this information. , but the current front-end is packaged through webpack. Even if code splitting is done, the js files and css files are still very large.

In the case of first loading, there is some room for optimization. The following mainly introduces some ways to obtain information. The interface uses simulated data, and the session acquisition interface is set to a 1 second delay. The following data are all data loaded for the first time, regardless of the 304 situation.

php Chinese website learning topicphp session (including pictures, texts, videos, cases)

 1. After End program settings, direct js code, global variable writing method

The browser accesses app.do, the backend program responds, obtains the user information InitData, obtains the returned app.html text, and writes the user information Write to the corresponding location of html and return to the browser

 [Problem]

a. Obtain user information InitData + app. html text ---→ Return to the browser, and the browser loads other static resources----> html loading process

b. The html returned by app.do, because the basic information of each user is Different, there is no way to use the browser 304 caching mechanism

 2. The page is loaded synchronously through