ActionsDev

10 replies to this thread. Most Recent

waltd

31 Dec 2012, 6:31 pm

FreewayPro CDN

I launched a little thing late Saturday night. I was working on a quickie Action for TableKit, which I still haven’t gotten around to adding to ActionsForge and documenting and all, and I wanted to link to all of the assets rather than rolling up a bundle Action. I looked on Google’s CDN, and even CDNJS (Cloudflare’s new all-access CDN) and didn’t see TableKit anywhere. I could add it there, but I wanted to see how hard it would be to make my own CDN. After all, I’ve been hosting all of the videos for FreewayCast on Amazon S3 for years, it’s rarely over $0.50 per month to do that, and with Amazon’s CloudFront service, you can expose S3 to the world through a huge network of edge cache servers without writing any code.

So here’s the steps involved:

  1. Create a bucket on S3. Mine is called ajax-cdn.s3.amazonaws.com.
  2. Upload some files to it. (I used Transmit for this.)
  3. Select the bucket, choose Get Info, and set it to be world-readable, and copy those permissions to all contained objects.
  4. Still in the Get Info inspector, check the “Distribute Using CloudFront” box. Copy the domain name of the server created by this step.
  5. At your favorite DNS provider, create a new CNAME record in your domain that maps your subdomain of choice to the CloudFront server.
  6. Log into the AWS (Amazon Web Services) portal, and move to the CloudFront page. Locate your server in the Distributions list, and open up the Edit screen. Add the custom subdomain you created in step 5 and save changes.

In about 15 minutes, you have a working CDN. Any files you add to the server will be available momentarily throughout the world through a network of servers that are geographically close to your users, no matter where they may live. And that makes the difference between having to roll up a bundle Action, with all of the resources your Action needs hidden inside it, and being able to do something simple and declarative like this instead:

function fwBeforeEndHead(){
  addPrototype();
  if(!fwPage.tablekit){
    var head = fwDocument.fwTags.fwFind('head');
    fwPage['tablekit'] = true;
    var script = head.fwAdd('script', true);
    script.src = fwQuote('http://cdn.freewaypro.com/tablekit/1.3/tablekit.js');
    script.type = fwQuote('text/javascript');
    script.charset = fwQuote('utf-8');
    script.fwAddRawOpt('');
    head.fwAddRawOpt('');

    var link = head.fwAdd('link');
    link.href = fwQuote('http://cdn.freewaypro.com/tablekit/1.3/css/style.css');
    link.type = fwQuote('text/css');
    link.rel = fwQuote('stylesheet')
    link.charset = fwQuote('utf-8');
    head.fwAddRawOpt('');
  }
}

It’s better for you, and your users, and it costs next to nothing. I’m petitioning Softpress to offer this as a service to Action developers, and I plan to write a simple Rails front-end next year to allow an admin to upload files quickly and simply.

For the short term, if you want to try this out, send me your files and I’ll load them up for you. If the underlying storage changes hands from me to Softpress, there won’t be any disruption in the URL. We’ll have to collaborate on naming and versioning, though. At the moment, it’s organized like this:

/ajax-cdn/
    /tablekit/
        /1.3/
            /css/
            /images/
            tablekit.js

The one thing that CDNs make very painful is deleting or changing something after you’ve added it to the system. That’s why the 1.3 is there. If I rev this script or the files, I will just make a new version folder like 1.3.1 or 1.4, and put the new files in there. Adding is cheaper than changing, at least in terms of effort.

I’d heard rumblings from various developer blogs that this was easy, but I never realized just how easy until I tried.

Happy new year to all, and keep writing Actions!

Walter

Freeway user since 1997

http://www.walterdavisstudio.com

DeltaDave

31 Dec 2012, 9:25 pm

Always going the extra mile - thanks Walter.

D

Glasgow, Scotland

iMac 27 5K El Cap and Pro Final

waltd

11 Jan 2013, 6:52 pm

http://cdnadmin.freewaypro.com

If you want to sign up for an account here, you can add your scripts and other resources needed in your Actions to my CDN. Just let me know when you’ve signed up, so I can vet your account and approve you as an author.

Walter

On Dec 31, 2012, at 5:25 PM, DeltaDave wrote:

Always going the extra mile - thanks Walter.

D

Freeway user since 1997

http://www.walterdavisstudio.com

DeltaDave

11 Jan 2013, 9:51 pm

Any restrictions on what you can host there - script/asset wise.

Is it all accessible to everyone - dont want to embarrass myself too much.

D

Glasgow, Scotland

iMac 27 5K El Cap and Pro Final

waltd

11 Jan 2013, 9:57 pm

I really need to post a TOS, but if I were to write one on a cocktail napkin (with a fat crayon) it would be “don’t be a d*ck, and don’t abuse my generosity”. I will take down anything I don’t think meets those criteria, and I won’t approve anyone who I don’t have a little faith in.

Take a look at what I have up there so far — mostly tiny JS files and some images and stylesheets. The idea is to work hand-in-hand with the new Protaculous 2 and other Actions written to act like it. It’s not there to host your 2.3MB background images 8-).

The assets you post are immediately world-readable, and will populate across Amazon’s global CDN within 15 minutes of you posting. It is incredibly hard to take anything down once posted, so don’t try. Just put a newer version up and switch the link.

Walter

On Jan 11, 2013, at 5:51 PM, DeltaDave wrote:

Any restrictions on what you can host there - script/asset wise.

Is it all accessible to everyone - dont want to embarrass myself too much.

D

Freeway user since 1997

http://www.walterdavisstudio.com

DeltaDave

12 Jan 2013, 12:06 am

The assets you post are immediately world-readable, and will populate across Amazon’s global CDN within 15 minutes of you posting. It is incredibly hard to take anything down once posted…

Scary!

I will give it some thought.

Glasgow, Scotland

iMac 27 5K El Cap and Pro Final

waltd

12 Jan 2013, 12:49 am

Here’s the thing. It costs nearly nothing to put files on this server. Once I put them in my S3 “bucket” they are automagically copied around the world and cached everywhere. To get them out of the cache, I have to issue a request for a specific path that I want to have invalidated, using a clunky control panel in the AWS site. Removing the file from S3 doesn’t do that — it just makes the original go missing. But the cache copies are on extremely long time-to-live. (No idea exactly how long, but imagine it’s something like a year.) So the fact that I delete it from S3 means exactly nothing in the big picture, since nobody except CloudFront servers that haven’t been built yet will ever look there for it. Everyone else gets it from the edge cache.

Walter

On Jan 11, 2013, at 8:06 PM, DeltaDave wrote:

The assets you post are immediately world-readable, and will populate across Amazon’s global CDN within 15 minutes of you posting. It is incredibly hard to take anything down once posted…

Scary!

I will give it some thought.

Freeway user since 1997

http://www.walterdavisstudio.com

waltd

12 Jan 2013, 12:52 am

For example, look at this page: http://cdnadmin.freewaypro.com/libraries/1 It took me a number of tries to get the thing to work correctly, and so what I did was post a new library each time I fixed something, and then rev the version number in my Action to match. Updating the file on S3 did nothing, just frustrated me. And the AWS control panel is a special form of torture.

Walter

On Jan 11, 2013, at 8:49 PM, Walter Lee Davis wrote:

So the fact that I delete it from S3 means exactly nothing in the big picture, since nobody except CloudFront servers that haven’t been built yet will ever look there for it. Everyone else gets it from the edge cache.

Freeway user since 1997

http://www.walterdavisstudio.com

JDW

21 Dec 2016, 7:50 am

Walter, not that this matters too much now that Freeway is no longer developed, but I thought it best to mention anyway. I was checking my sites with a performance checker and it mentioned that none of the files served on your CDN have GZIP compression. Amazon’s CloudFront service makes that available as an option, as described here:

https://aws.amazon.com/blogs/aws/new-gzip-compression-support-for-amazon-cloudfront/

Just change the “Compress Objects Automatically” radio button to “Yes” and click the “Yes, Edit” button. That’s it.

Best wishes,

James Wages

waltd

21 Dec 2016, 2:42 pm

Well that was painful! Took ages to find the control panel, but seconds to make the change. Give it some time to propagate, and then let me know how it goes.

Walter

On Dec 21, 2016, at 2:50 AM, JDW <[email protected]> wrote:

Walter, not that this matters too much now that Freeway is no longer developed, but I thought it best to mention anyway. I was checking my sites with a performance checker and it mentioned that none of the files served on your CDN have GZIP compression. Amazon’s CloudFront service makes that available as an option, as described here:

https://aws.amazon.com/blogs/aws/new-gzip-compression-support-for-amazon-cloudfront/

Just change the “Compress Objects Automatically” radio button to “Yes” and click the “Yes, Edit” button. That’s it.

Best wishes,

James Wages

Freeway user since 1997

http://www.walterdavisstudio.com

Back to Top

JDW

22 Dec 2016, 1:01 am

Thanks, Walter.

Yesterday I was using the following to check my sites:

https://developers.google.com/speed/pagespeed/insights/

I’m not seeing any Freeway CDN files listed under “Minify JavaScript” now (which includes GZIP), so I think everything has propagated.

The really funny part is that the only URLs it now complains about under “Leverage browser caching” & “Minify JavaScript” are Google URLs:

http://www.google-analytics.com/plugins/ua/linkid.js

http://www.google-analytics.com/analytics.js

http://ajax.googleapis.com/ajax/libs/prototype/1.7/prototype.js

http://ajax.googleapis.com/ajax/libs/scriptaculous/1.9/effects.js

You’d think they’d compress and set cache expiry times for their own stuff!

Best wishes,

James W.