One page only javascript applications

前端 未结 8 836
野性不改
野性不改 2021-02-08 23:09

Have you experimented with single page web application, i.e. where the browser only \'GETs\' one page form the server, the rest being handled by client side javascript code (one

8条回答
  •  南笙
    南笙 (楼主)
    2021-02-09 00:08

    I call these single page apps "long lived" apps.

    For "simpler applications" as you put it it's terrible. Things that work OOTB for browsers all of a sudden need special care and attention:

    • the back button
    • the refresh button
    • bookmarking/copying url

    Note I'm not saying you can't do these things with single-page apps, I'm saying you need to make the effort to build them into the app code. If you simply had different resources at different urls, these work with no additional developer effort.

    Now, for complex apps like gmail, google maps, the benefits there are:

    • user-perceived responsiveness of the application can increase
    • the usability of the application may go up (eg scrollbars don't jump to the top on the new page when clicking on what the user thought was a small action)
    • no white screen flicker during the HTTP request->response

    One concern with long-lived apps is memory leaks. Traditional sites that requests a new page for each user action have the added benefit that the browser discards the DOM and any unused objects to the degree that memory can be reclaimed. Newer browsers have different mechanisms for this, but lets take IE as an example. IE will require special care to clean up memory periodically during the lifetime of the long-lived app. This is made somewhat easier by libraries these days, but by no means is a triviality.

    As with a lot of things, a hybrid approach is great. It allows you to leverage JavaScript for lazy-loading specific content while separating parts of the app by page/url.

提交回复
热议问题