How to use Precompressed for 2 files only

Chat GPT suggested this:

:88 {
    encode zstd gzip

    handle /js/all.js {
        try_files /js/all.js.gz /js/all.js
        file_server
        @gzip_js {
            file /js/all.js.gz
        }
        header @gzip_js Content-Encoding gzip
        header Content-Type application/javascript
    }

    handle /css/all.css {
        try_files /css/all.css.gz /css/all.css
        file_server
        @gzip_css {
            file /css/all.css.gz
        }
        header @gzip_css Content-Encoding gzip
        header Content-Type text/css
    }

    handle {
        reverse_proxy localhost:4000 localhost:4001 {
            lb_policy least_conn
        }
    }

    log {
        output file logfile.log
        format console
        level ERROR
    }

    tls ..\pem.pem ..\key.key
}

and it works fine, it even works without all.js and all.css files (there are only GZipped files exists).
Can someone confirm this, please? Is it safe to use such Caddyfile and only gz files? Thank you.