-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
CDN Hosting at Google Cloud Storage
Note: these are preliminary notes about using Google Cloud Storage as a CDN service
The documentation home is https://developers.google.com/storage/index. The main tool is gsutil
. Note: due to rapid development a lot of information on the web uses outdated syntax (but is still useful, e.g., https://gist.github.com/mhulse/4362104).
Notes: recursively (-R), compressed (-z), verbose (-v) https://developers.google.com/storage/docs/gsutil/commands/cp
gsutil cp -Rzv mathjax gs://mathjax-cdn/
This also works within google storage (which is faster as it does not go through the local machine).
Notes: https://developers.google.com/storage/docs/gsutil/commands/acl#set
gsutil -m setacl -R -a public-read gs://mathjax-cdn
Notes: should only be needed once, https://developers.google.com/storage/docs/cross-origin
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/
Notes: https://developers.google.com/storage/docs/gsutil/commands/setmeta
gsutil setmeta -r -h "Content-Type:font/opentype" -h "Cache-Control:public, max-age=3600" -h "Content-Disposition" gs://mathjax-cdn/mathjax/2.3-latest/fonts/HTML-CSS/TeX/otf/*.otf
EOT and SVG are detected correctly during upload. WOFF is set to the old x-font/woff
, so needs changing (and a bug report at Google).
Note: unfortunately we can't just use something like gs//mathjax-cdn/*.otf (or cane we? https://developers.google.com/storage/docs/gsutil/addlhelp/WildcardNames)