애플리케이션은 종종 동적 요청을 처리하는 것 외에도 JavaScript, 이미지 및 CSS와 같은 정적 파일을 제공해야 합니다. 표준 환경의 앱은 Cloud Storage와 같은 Google Cloud 옵션에서 정적 파일을 제공하거나 직접 제공하거나 타사 콘텐츠 전송 네트워크(CDN)를 사용할 수 있습니다. Google Cloud에서 정적 사이트를 호스팅하면 기존 호스팅을 사용하는 것보다 비용이 적게 듭니다. Google Cloud에서 무료 등급을 제공하므로 제공업체 ## Cloud Storage에서 파일 제공 Cloud Storage는 동적 웹 앱의 정적 자산을 호스팅할 수 있습니다. 앱에서 직접 제공하는 대신 Cloud Storage를 사용하면 다음과 같은 이점이 있습니다. - Cloud Storage는 기본적으로 콘텐츠 전송 네트워크로 작동합니다. 기본적으로 읽을 수 있는 개체는 글로벌 Cloud Storage 네트워크에 캐시되므로 특별한 구성이 필요하지 않습니다. - 정적 자산 제공을 Cloud Storage로 오프로드하여 앱의 로드가 줄어듭니다. 보유하고 있는 정적 자산의 수와 액세스 빈도에 따라 앱 실행 비용을 크게 줄일 수 있습니다. - 콘텐츠 액세스에 대한 대역폭 요금은 Cloud Storage를 사용하면 종종 더 적을 수 있습니다. 다음을 사용하여 애셋을 Cloud Storage에 업로드할 수 있습니다. gsutil 명령줄 도구 또는 Cloud Storage API Google Cloud 클라이언트 라이브러리는 App Engine 앱에서 Cloud Storage로 데이터를 저장하고 검색하기 위해 Cloud Storage에 관용적인 Go 1.11 클라이언트를 제공합니다. Cloud Storage 버킷에서 제공하는 예 이 간단한 예는 Cloud Storage 버킷을 만들고 Google Cloud CLI를 사용하여 정적 자산을 업로드합니다. 버킷을 생성합니다. 프로젝트 ID를 따라 버킷 이름을 지정하는 것이 일반적이지만 필수는 아닙니다. 버킷 이름은 전역적으로 고유해야 합니다. gsutil mb gsyour-bucket-name>버킷의 항목에 대한 읽기 액세스 권한을 부여하도록 ACL 설정 gsutil defacl set public-read gsyour-bucket-name>항목을 버킷에 업로드합니다. 그만큼 rsynccommand는 일반적으로 자산을 업로드하고 업데이트하는 가장 빠르고 쉬운 방법입니다. 당신은 또한 사용할 수 있습니다 CP gsutil -m rsync -r ./static gsyour-bucket-name>/static 이제 다음을 통해 정적 자산에 액세스할 수 있습니다. 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.