Skip to content

CDN Hosting at Google Cloud Storage

Peter Krautzberger edited this page Feb 26, 2014 · 34 revisions

Note: these are preliminary notes about using Google Cloud Storage as a CDN service

Preliminaries

Copying

Notes:

  • gsutil option: -m multithreaded (higher load+cost, faster)

  • cp options: recursively (-R), compressed (-z), verbose (-v) https://developers.google.com/storage/docs/gsutil/commands/cp

  • Note: compressed is necessary to get gzipped delivery. Google Cloud storage does not compress on the fly but should decompress on the fly for old browsers that can't accept decompressed files.

      gsutil -m cp -Rzv mathjax gs://mathjax-cdn/
    

This also works within google storage, i.e., gsutil cp gs://bucket1/file1 gs://bucket2/

make bucket public

Notes:

set CORS

Notes:

create XML file with

<?xml version="1.0" encoding="UTF-8"?>
<CorsConfig>
  <Cors>
        <Origins>
            <Origin>*</Origin>
        </Origins>
        <Methods>
            <Method>GET</Method>
            <Method>POST</Method>
            <Method>HEAD</Method>
        </Methods>
        <ResponseHeaders>
            <ResponseHeader>*</ResponseHeader>
        </ResponseHeaders>
        <MaxAgeSec>86400</MaxAgeSec>
    </Cors>
</CorsConfig>

Save as cors.xml and run

gsutil cors set cors.xml gs://fonts.acmecompany.com/

mime-type headers

Notes:

TODO

  • tests -- we don't actually have any tests that check the functionality of the CDN.
    • CORS
    • mimetype
  • change caching time. Something like $ gsutil -m setmeta -r -h "Cache-Control:public, max-age=7776000" gs://mathjax-cdn/mathjax/ but we don't want to apply this to MathJax.js. Not sure how to do this efficiently.

Clone this wiki locally