Aplikasi asring kudu nyedhiyakake file statis kayata JavaScript, gambar, lan CSS saliyane nangani panjalukan dinamis. Aplikasi ing lingkungan standar bisa nglayani file statis saka opsi Google Cloud kaya Cloud Storage, dilayani kanthi langsung, utawa nggunakake jaringan pangiriman konten (CDN) pihak katelu. panyedhiya, amarga Google Cloud nyedhiyakake undakan gratis ## Nglayani file saka Cloud Storage Cloud Storage bisa dadi host aset statis kanggo aplikasi web dinamis. Keuntungan nggunakake Cloud Storage tinimbang ngladeni langsung saka app sampeyan kalebu: - Cloud Storage ateges bisa digunakake minangka jaringan pangiriman konten. Iki ora mbutuhake konfigurasi khusus amarga kanthi gawan sembarang obyek sing bisa diwaca di-cache ing jaringan Cloud Storage global - Muatan aplikasi sampeyan bakal suda kanthi ngunggahake aset statis menyang Cloud Storage. Gumantung saka jumlah aset statis sing sampeyan duwe lan frekuensi akses, iki bisa nyuda biaya mbukak aplikasi kanthi jumlah sing signifikan. - Biaya bandwidth kanggo ngakses konten asring luwih murah karo Cloud Storage Sampeyan bisa ngunggah aset menyang Cloud Storage kanthi nggunakake alat baris printah gsutil utawa Cloud Storage API Pustaka Klien Awan Google nyedhiyakake klien Go 1.11 idiomatik menyang Cloud Storage, kanggo nyimpen lan njupuk data nganggo Cloud Storage ing aplikasi App Engine Conto porsi saka ember Cloud Storage Conto prasaja iki nggawe ember Cloud Storage lan ngunggah aset statis nggunakake Google Cloud CLI: Nggawe ember. Biasane, nanging ora dibutuhake, kanggo menehi jeneng ember sawise ID proyek sampeyan. Jeneng ember kudu unik sacara global gsutil mb gsyour-bucket-name>Setel ACL kanggo menehi akses maca menyang item ing ember gsutil defacl nyetel public-read gsyour-bucket-name>Upload item menyang ember. Ing rsynccommand biasane cara paling cepet lan paling gampang kanggo ngunggah lan nganyari aset. Sampeyan uga bisa nggunakake cp gsutil -m rsync -r ./static gsyour-bucket-name>/static Sampeyan saiki bisa ngakses aset statis liwat httpsstorage.googleapis.com//static For more details on how to use Cloud Storage to serve static assets, including how to serve from a custom domain name, refer to How to Host a Static Website Serving files from other Google Cloud services You also have the option of using Cloud CDN or other Google Cloud storage services ## Serving files directly from your app To serve static files for Go 1.11 in the standard environment, you define the handlers in your app.yaml file using either the static_dir or static_files elements The content in the static files or static directories are unaffected by the scaling settings in your app.yaml file. Requests to static files or static directories are handled by the App Engine infrastructure directly, and do not reach the language runtime of the application Configuring your static file handlers To configure your app to serve the ./public directory from the /static URL, you define a handler in your app.yaml file The following demonstrates how to serve the static files of a sample app's ./public directory. The template for this app's index.html page instructs the browser to load the main.css file, for example: /css/main.css"> The ./public directory is defined in the static_dir element of the project's app.yaml file: handlers: - url: /favicon\.ico static_files: favicon.ico upload: favicon\.ico - url: /static static_dir: public - url:secure: always redirect_http_response_code: 301 script: auto The handlers section in the above example handles three URL patterns: The /favicon.icohandler maps a request specifically for /favicon.icoto a file named favicon.icoin the app's root directory The /statichandler maps requests for URLs that start with /static. When App Engine receives a request for a URL beginning with /static, it maps the remainder of the path to files in the ./publicdirectory. If an appropriate file is found in the directory, the contents of that file are returned to the client The handler matches all other URLs and directs them to your app URL path patterns are tested in the order they appear in app.yaml, therefore the pattern for your static files should be defined before the pattern For more information, see the app.yaml reference ## Serving from a third-party content delivery network You can use any external third-party CDN to serve your static files and cache dynamic requests but your app might experience increased latency and cost For improved performance, you should use a third-party CDN that supports CDN Interconnect.