1

I'm building a purely client side JavaScript based web app, and am looking to optimize the workflow for switching to CDN URLs for the JavaScript libraries I use on the production server.

In order to be able to do work offline, my laptop development machine loads all the libraries from a /js folder on a local web server. When I deploy the app, I want to substitute these URLs to use CDN versions of the jQuery library on Google e.g.. Since there's no server side logic, I can't make a check there for something like Rails.env.production? like I would if this were a Rails app.

I'm deploying by pushing to a git repo on the production machine and running a post-receive hook. I imagine I could run some kind of sed routine that switches URLs over the update in the same post-receive script, but am curious if there's not maybe a more elegant solution.

The easiest thing would be to simply put client side logic into the app to check what hostname it was called form, but I'd like to keep that as a last resort.

There is a previous discussion on fallback loading here, but a broader sense my question is about the automated swapping out of a block of text for another when deploying to a production machine.

Community
  • 1
  • 1
Joost Schuur
  • 4,417
  • 2
  • 24
  • 39
  • Have you tried using build tools such as ANT to deploy from local environment to production ? – Marc Bouvier Apr 24 '11 at 20:49
  • I wasn't familiar with ANT until you just mentioned it, and from looking at their docs, it seems like a bulky tool that would ultimately jus result in me calling a sed script, which I might as well do in git's post-receive hook. – Joost Schuur Apr 24 '11 at 21:07

2 Answers2

1

You want to commit the change that has the pointer to the CDN version on the branch from which you will be publishing.

Commit the change that will have the development version to your development branch.

Assuming that this is the only way your branches differ, merge with "ours" strategy on both branches.

git merge -s ours mainbranch

This will ensure that you don't get that code change from now on wherever you merge or rebase.

hope this helps.

Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141
0

You could simply make the CDN host work locally by adding it to your /etc/hosts.

If that's not an option, use inline JavaScript to add the <script src="..." tags to the document and put some logic to decide whether to use CDN or not into that script.

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
  • Modifying the hosts file assumes I'll be caching any file served from the host, which is a big assumption. The latter would work, but really limits the scope to script loading. I'm looking for something more generic that allows me to modify content after a push on the production environment. – Joost Schuur Apr 24 '11 at 21:05