Skip to content

Instantly share code, notes, and snippets.

@konklone
Last active August 29, 2015 14:08
Show Gist options
  • Save konklone/f681524082bb77b89ad3 to your computer and use it in GitHub Desktop.
Save konklone/f681524082bb77b89ad3 to your computer and use it in GitHub Desktop.
Instructions for minifying, compressing, and uploading the DAP

Hosting the DAP Snippet

Where dap-1.0.js is the current, unminified version of the DAP UA snippet.

Minifying

Generate a minified version of the snippet, and an accompanying source map, using uglifyjs.

Install uglifyjs through npm (which comes with Node):

npm install -g uglifyjs

Then run it, specifying the source map:

uglifyjs dap-1.0.js --source-map=dap-1.0.min.js.map > dap-1.0.min.js

This gives you three files: dap-1.0.js, dap-1.0.min.js (minified), and dap-1.0.min.js.map (source map).

Compressing

Most file servers will automatically bake compression (gzip) into the process, automatically compressing them as needed (this is called compression scheme negotiation). Amazon S3 does not do this, so we need to compress the files ourselves.

Create a compressed (gzipped) version of all 3 files:

gzip -c dap-1.0.min.js > dap-1.0.min.js.gz
gzip -c dap-1.0.min.js.map > dap-1.0.min.js.map.gz
gzip -c dap-1.0.js > dap-1.0.js.gz

Uploading

Upload each gzipped file to an Amazon S3 bucket, using s3cmd. The below commands instruct Amazon S3 to serve files as JavaScript, and to mark their encoding as gzip, so that browsers will know to automatically unzip the files before reading them. Note that the files are renamed upon upload to remove the .gz suffix.

s3cmd put -P --mime-type="application/javascript" --add-header="Content-Encoding: gzip" dap-1.0.js.gz s3://18f-dap/dap-1.0.js
s3cmd put -P --mime-type="application/javascript" --add-header="Content-Encoding: gzip" dap-1.0.min.js.gz s3://18f-dap/dap-1.0.min.js
s3cmd put -P --mime-type="application/javascript" --add-header="Content-Encoding: gzip" dap-1.0.min.js.map.gz s3://18f-dap/dap-1.0.min.js.map

Finally, configure this S3 bucket to be the source for an Amazon CloudFront distribution. This has been provisioned temporarily at https://dvs6mwdoj87wa.cloudfront.net. (HTTPS only - http:// links will not redirect.)

Example URL:

https://dvs6mwdoj87wa.cloudfront.net/dap-1.0.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment