Applicaties moeten naast het afhandelen van dynamische verzoeken vaak ook statische bestanden leveren, zoals JavaScript, afbeeldingen en CSS. Apps in de standaardomgeving kunnen statische bestanden aanbieden vanuit een Google Cloud-optie zoals Cloud Storage, ze rechtstreeks aanbieden of een extern content delivery network (CDN) gebruiken. Het hosten van uw statische site op Google Cloud kan goedkoper zijn dan het gebruik van een traditionele hosting provider, aangezien Google Cloud een gratis laag biedt ## Bestanden aanbieden vanuit Cloud Storage Cloud Storage kan statische activa hosten voor dynamische web-apps. De voordelen van het gebruik van Cloud Storage in plaats van rechtstreeks vanuit uw app te dienen, zijn onder andere: - Cloud Storage werkt in wezen als een netwerk voor het leveren van inhoud. Hiervoor is geen speciale configuratie vereist, omdat elk leesbaar object standaard wordt gecached in het wereldwijde Cloud Storage-netwerk - De belasting van uw app wordt verminderd door statische activa te ontladen naar Cloud Storage. Afhankelijk van hoeveel statische activa u heeft en de frequentie van toegang, kan dit de kosten van het uitvoeren van uw app aanzienlijk verlagen - Bandbreedtekosten voor toegang tot inhoud kunnen vaak lager zijn met Cloud Storage U kunt uw middelen uploaden naar Cloud Storage met behulp van de gsutil-opdrachtregelprogramma of de Cloud Storage-API De Google Cloud Client Library biedt een idiomatische Go 1.11-client voor Cloud Storage, voor het opslaan en ophalen van gegevens met Cloud Storage in een App Engine-app Voorbeeld van weergave vanuit een Cloud Storage-bucket Dit eenvoudige voorbeeld maakt een Cloud Storage-bucket en uploadt statische activa met Google Cloud CLI: Maak een emmer. Het is gebruikelijk, maar niet verplicht, om uw bucket de naam van uw project-ID te geven. De bucketnaam moet wereldwijd uniek zijn gsutil mb gsuw-bucket-naam>Stel de ACL in om leestoegang te verlenen aan items in de bucket gsutil defacl set public-read gsyour-bucket-name>Upload items naar de bucket. De rsynccommand is doorgaans de snelste en gemakkelijkste manier om middelen te uploaden en bij te werken. Je zou ook kunnen gebruiken kp gsutil -m rsync -r ./static gsuw-bucketnaam>/static U heeft nu toegang tot uw statische activa via httpsopslag.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.