https://learnku.com/articles/…

The environment

Php7.4 nginx1.17 mysql5.7 Windows 10

route

  • Do this when the controller returns to the view
    public function test(Request $request) {
        $view =  view('test')->render();
        Storage::disk('local')->put('views/' . $request->path(), $view);
        return $view;
    }
  • The NGINX configuration writes this
location / {  
    root D:/wwwroot/demo/storage/app/views;
    index index.html;
    try_files $uri $uri.html @default;
}
location @default {
    root D:/wwwroot/demo/public;
    index index.php;
    try_files $uri $uri/ /index.php$is_args$query_string;
}

This will generate the corresponding static page on the first visit and return the static page directly on subsequent visits.

  • further

The implementation of expired delete, automatic update function, probably is to get all the file names in the Views folder, recorded, and then regularly clear, can also take the initiative to issue a request to trigger the update. The other is lossless full-site statics, which requires overwriting the view() method in Foundations/ Helpers.php. However, this file has been created with auto-load mappings, which normally cannot be overwritten. You can install FunkJedi /composer-include-files and it will automatically load your custom PHP files first, and that’s OK.

  • Certification status

Usually need to display the current login user’s avatar, after the static can not display? B: Sure.

For example, after authentication, user data is saved to the browser, and the current state is updated to static HTML via JS.


The Laravel Universal Plug-in System enables you to hot-plug your Laravel projects!