A place to breathe

Saturday, September 6, 2014

Enter Middleman

Now that we have our Rails box setup, we can try a few simple static page deployment. Without complicating my life, I opted to run my static files on "Rackspace" server. You can think of "rack" as just makefiles for Rails. Rack can "compile" your static page and auto-publish for you. More on this later. An example of Rackspace server is Heroku.

So a brief overview of some latest web philosophy: Static page.

Because the traditional website queries database while loading, this is just bad. It makes the loading slower and you can loose out your audience attention. So some smart people came up with a smart solution: use static page with front end javascript to load things faster and interact up front with your audience, and at the same time, the static page go calls API of some remote server (that is, our Rails server in this context), to fetch some data.

The javascript front-end plays important role. It does some magical stuff like auto-update (as if the data exists, before even getting some data), do some animation or whatever. Up to you. The point is, don't wait for data to come before interacting with users. You can think of javascript as a receptionist who entertains you with a glass of lemon juice and giving you newspaper to read while waiting for her boss to come over to meet you to give you information on whatever you need from the boss.

Now that your know why we need static page with javascript front-end, we can turn our attention a slightly advance mechanism to "compile" our static page. The app is called "Middleman". Middleman enable us to generate static files and doing some cool stuff on static data and mark ups.

Now go to your vagrant box:

vagrant ssh 
cd /vagrant 

Install middleman

gem install middleman 
middleman init my_project
cd my_project

Check your gemfile inside my_project. don't forget to check your gem files to have :

'therubyracer'
'execjs'
'rb-inotify'

Actually, you can depend on your big Rails Gemfile but I just got errors this way. Run:

bundle exec middleman build 
bundle exec middleman server -p 3000 

Now, you need to run it with port 3000. This is because we have configured our box to display the port 3000.

After executing these commands, go to your browser:

http://localhost:3000. 

See something? Rejoice !










No comments:

About Me

I'm currently a software engineer. My specific interest is games and networking. I'm running software company called Nusantara Software.