Static Sites on Heroku in Two Lines 29
Sometimes you just have a static website with one or a couple pages. You might even have a shared hosting plan or even a VPS but who wants to go through the hassle of that when you could use Heroku?
Here is a simple way to host your static site and cache it on Heroku using a Rack app.
Here is how your folder should be organized:
In the config.ru file add the following:
This assumes that your template uses relative references to the images and stylesheets. Go ahead and deploy the app, if you are not sure how to deploy to Heroku check out their quickstart guide.
Now since Heroku uses a HTTP Accelerator we should take advantage of it. If you noticed in the config.ru file we set the Cache-Control header to 86400 seconds (24 hours). This tells the accelerator to go ahead and cache the page. The accelerator already caches any Rack::File for 12 hours as well meaning all your stylesheets and images will also be cached.
To confirm it's working, let's take a look at the HTTP headers returned from your site. The Age header indicated that it's being served from the HTTP cache.
And there you go, a static site being served in Heroku's cloud completely cached and for free.
Trackbacks
Use the following link to trackback from your own site:
http://mwhuss.com/trackbacks?article_id=9



Is it possible to force clear a particular page or image from the cache?
Yes, every time you push to Heroku and deploy the entire cache is expired.
Yeah I heard about the push method
Just seems scary to need to wipe the entire cache to clear one asset :)
Nice post. If you want to use jekyll pages on Heroku or any vps server , try Rack-Jekyll.
It can recompile pages if _site directory is emptied and it supports custom 404 page. You can add any rack middleware with it like Rack::Cache and others :-)
That works great for a one page site. How do I make it work for, say, a three page site with index.html, about.html, and contact.html?
Okay, here’s a solution. I don’t know anything about Rack, but I added the two pages to the :urls array argument like this:
use Rack::Static, :urls => [“/stylesheets”, “/images”, “/about.html”, “/contact.html”], :root => “public”
And now it works. Had to refresh each page, probably because of the caching.
Thanks @Scott, I will add those notes to the original entry.
Nice find Marshall.
If you want to serve everything, just drop a regex into :urls.
This will find and serve everything :-)
use Rack::Static, :urls => [/./], :root => “public”
dd those notes to t
roblems with the following fields:
This article gives the light in which we can observe the reality. this is very nice one and gives indepth information. thanks for this nice article. gps tracking systems
Yes! This is time to show qt’s misrable in the real appliance, not about license
Of course, we need a static website when works,but sometimes it cant do as we wish using the heroku.
Some of its members also had punk rock background. , grady white jell coat.com, [url=”http://hg2.stonehitaccess.com/grady-white-jell-coat.com.html”]grady white jell coat.com[/url], http://hg2.stonehitaccess.com/grady-white-jell-coat.com.html grady white jell coat.com, slqi,
Thanks for this great post. Did you do it all on your own? This must’ve taken a lot of time
This is the greatest topic I have read today
Thanks for this great post. Did you do it all on your own? This must’ve taken a lot of time
Jljkie http://gdjI3b7VaWpU1m0dGpvjRrcu9Fk.com
Thank you for this information. I’ve been looking for something like this for quite a while. Keep up the good work, cheers! klimat thailand lången tips filippinerna
Cheers man, I’ve been looking for a guide like this for quite some time now. reservdelar mg reservdelar mini reservdelar land rover
Thanks for a good post. Keep em coming bro! synas på google places restaurang karlstad
Thanks for a good post. Keep em coming. Hope this blog will never come to an end. synas på google places restaurang karlstad
This is some great blog. Too bad you stoped blogging. synas på google places
Now thats an easy way to get a static page. And it is cached. What more i am going to ask
It’s a bad line youngchild bra models >:]]]
I’ve been made redundant Killah Bbw Toplist >:-P
I enjoy travelling Lily Model Dvd 023651
Great post again! Thank you for sharing this info with us!
Good share again! Static sites is just about this stuff. Thanks. Bilverkstad i växjö.