Skip to content

CDN Hosting at Google Cloud Storage

Peter Krautzberger edited this page Mar 28, 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:

caching

This is a one time task. Proposed caching is 3 months for all but MathJax.js which gets 1 week.

    $ gsutil -m setmeta -r -h "Cache-Control:public, max-age=7776000" gs://mathjax-cdn/mathjax/
    $ gsutil -m setmeta -r -h "Cache-Control:public, max-age=3600" gs://mathjax-cdn/mathjax/**/MathJax.js

This is theoretically risky. Since caching can only be specified after making the file public, it could theoretically happen that MathJax.js is called and cached before the second command runs -- fixing it to a 3 month caching that cannot be undone.

Well, it didn't happen. So we're good.

Logging

For logging, follow https://developers.google.com/storage/docs/gsutil/commands/logging

TODO

  • tests.

    • CORS [vital]
      • A simple test: switch mathjax.org over to the origin. user browsershots/browserstack etc to check rendering across IE, FF, Chrome, Safari.
    • mimetype [non-vital]
      • write script to curl -I all woff and otf files, compare header.
  • swich over to new container mathjax (no idea why mathjax-cdn was chosen the first time around...)

  • document log analysis

Clone this wiki locally