How to force update Single Page Application (SPA) pages?

前端 未结 6 1847
生来不讨喜
生来不讨喜 2020-12-12 15:13

In fully server side based rendering (non Web 2.0), deploying server side code would directly update client side pages upon page reload. In contrast, in React based Single P

6条回答
  •  难免孤独
    2020-12-12 15:25

    I know this is an old thread, and service workers are probably the best answer. But I have a simple approach that appears to work:

    I added a meta tag to my "index.html" file :

    
    

    I then have a very simple php scrip in the same folder as the index.html that responds to a simple REST request. The PHP script parses the server copy of the index.html file, extracts the version number and returns it. In my SPA code, every time a new page is rendered I make an ajax call to the PHP script, extract the version from the local meta tag and compare the two. If different I trigger an alert to the user.

    PHP script:

    find('meta') as $e){
            if ( $e->name == $name){
                return $e->content ;
            }
        }
    }
    

提交回复
热议问题