Kadalasan kailangan ng mga application na maghatid ng mga static na file gaya ng JavaScript, mga larawan, at CSS bilang karagdagan sa paghawak ng mga dynamic na kahilingan. Ang mga app sa karaniwang kapaligiran ay maaaring maghatid ng mga static na file mula sa isang opsyon sa Google Cloud tulad ng Cloud Storage, direktang maghatid sa kanila, o gumamit ng third-party na content delivery network (CDN). Ang pag-host sa iyong static na site sa Google Cloud ay maaaring mas mura kaysa sa paggamit ng tradisyonal na pagho-host. provider, dahil nagbibigay ang Google Cloud ng libreng tier ## Naghahatid ng mga file mula sa Cloud Storage Maaaring mag-host ang Cloud Storage ng mga static na asset para sa mga dynamic na web app. Ang mga pakinabang ng paggamit ng Cloud Storage sa halip na direktang maghatid mula sa iyong app ay kinabibilangan ng: - Ang Cloud Storage ay mahalagang gumagana bilang isang network ng paghahatid ng nilalaman. Hindi ito nangangailangan ng anumang espesyal na configuration dahil bilang default, naka-cache ang anumang nababasang object sa pandaigdigang Cloud Storage network - Mababawasan ang pag-load ng iyong app sa pamamagitan ng pag-offload ng paghahatid ng mga static na asset sa Cloud Storage. Depende sa kung gaano karaming mga static na asset ang mayroon ka at ang dalas ng pag-access, maaari nitong bawasan ang gastos sa pagpapatakbo ng iyong app ng malaking halaga - Ang mga singil sa bandwidth para sa pag-access ng nilalaman ay kadalasang mas mababa sa Cloud Storage Maaari mong i-upload ang iyong mga asset sa Cloud Storage sa pamamagitan ng paggamit ng gsutil command line tool o ang Cloud Storage API Nagbibigay ang Google Cloud Client Library ng idiomatic na Go 1.11 client sa Cloud Storage, para sa pag-iimbak at pagkuha ng data gamit ang Cloud Storage sa isang App Engine app Halimbawa ng paghahatid mula sa isang Cloud Storage bucket Ang simpleng halimbawang ito ay gumagawa ng Cloud Storage bucket at nag-a-upload ng mga static na asset gamit ang Google Cloud CLI: Gumawa ng balde. Karaniwan, ngunit hindi kinakailangan, na pangalanan ang iyong bucket pagkatapos ng iyong project ID. Ang pangalan ng bucket ay dapat na natatangi sa buong mundo gsutil mb gsyour-bucket-name>Itakda ang ACL na magbigay ng read access sa mga item sa bucket gsutil defacl set public-read gsyour-bucket-name>Mag-upload ng mga item sa bucket. Ang Ang rsynccommand ay karaniwang ang pinakamabilis at pinakamadaling paraan upang mag-upload at mag-update ng mga asset. Maaari mo ring gamitin cp gsutil -m rsync -r ./static gsyour-bucket-name>/static Maa-access mo na ngayon ang iyong mga static na asset sa pamamagitan ng 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.