Where dap-1.0.js
is the current, unminified version of the DAP UA snippet.
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).
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
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: