Tuesday, April 03, 2007

Improve Rails Performance Through Eternal Browser Caching of Assets

I've been working on a rails app which has got quite a number of pages that share the same two css files and 3 javascript files. However, every time I visited any page of the app, all of javascripts and css files were being loaded from the server. Not good - site was very slow. Mucking around with 'about:cache' command in Firefox revealed that the css and javascript files had expiry dates set in the past - ie, no caching of them at all. Also, all the links to sylesheets and javascript files generated by rails had ?[some long number] after them. Some research on the web revealed that this is a new rails feature for caching - the long number is a timestamp for when the asset was last modified.

Okay, so why were these assets not being cached? A quick check with wget --save-headers revealed that the web server was sending a nocache directive to the browser. This seems to be the default setup for webrick and also for my shared apache hosting on railsplayground. Considering the new rails asset management system with the ?[last modified timestamp] in the URLs, nocache seems wrong. The browser should never expire the cache since rails will handle cache invalidation by updating the asset url with a new timestamp.

So, how can we implement no/very long cache expiry? In apache, you can use mod_expires or mod_headers to do this. My shared hosting does not support mod_expires, so I went for mod_headers in my .htaccess file.

Using mod_headers:
<FilesMatch "\.*$">
Header set Cache-Control "max-age=29030400"

OR using mod_expires:
ExpiresActive On
ExpiresDefault "access plus 1 year"

Either of the the above will set up a cache expiry time of one year for all content (best you only do this for your rails app directories).

With a cache expiry time of one year in place, my rails apps run much much faster.


Roger Pack said...

IMO if rails is in production mode it should definitely set the eternal caches you mention, for everything.
Take care :)

Anonymous said...

Now do you worried about that in the game do not had enough aion kina to play the game, now you can not worried, my friend told me a website, in here you can buy a lot aion online kina and only spend a little money, do not hesitate, it was really, in here we had much aion gold, we can sure that you will get the cheap aion kina, quick to come here to buy aion kina.

Now do you worried about that in the game do not had enough Anarchy credits to play the game, now you can not worried, my friend told me a website, in here you can buy a lot Anarchy Online credits and only spend a little money, do not hesitate, it was really, in here we had much Anarchy gold, we can sure that you will get the Anarchy online gold, quick to come here to buy AO credits.

Anonymous said...

















online cialis soft said...

generic viagra soft pharmacy online
generic cialis soft online
buy cialis cheap prices fast delivery
purchase viagra
full levitra information
purchase tadalafil cheap
cialis tadalafil cheapest online
buy tadalafil online
all information about cialis

Adi said...

Oes Tsetnoc one of the ways in which we can learn seo besides Mengembalikan Jati Diri Bangsa. By participating in the Oes Tsetnoc or Mengembalikan Jati Diri Bangsa we can improve our seo skills. To find more information about Oest Tsetnoc please visit my Oes Tsetnoc pages. And to find more information about Mengembalikan Jati Diri Bangsa please visit my Mengembalikan Jati Diri Bangsa pages. Thank you So much.

Anonymous said...

lovegra rezeptfrei
kamagra online kaufen
propecia rezeptfrei kaufen
actoplus met bestellen ohne rezept
actoplus met online kaufen
tamiflu rezeptfrei
zithromax online preisvergleich
viagra rezeptfrei kaufen
accutane kaufen ohne rezept
accutane apotheke rezeptfrei
accutane bestellen rezeptfrei
kamagra oral jelly bestellen rezeptfrei

Anonymous said...

viagra soft costo
zyban sr online vendita
vente silagra en pharmacie
viagra achat en ligne
acheter cialis soft en france
clomid vendita farmacia
viagra super active ohne rezept kaufen
farmacia senza ricetta
costo lovegra
achat cytotec pharmacie
accutane france
prezzo clomid farmacia
lasix en ligne

Negocio Rentable said...

I really like this blog, you are very good making them. I say that the issue discussed in this blog is quite interesting and of high quality.

Anonymous said...

clomid Rezeptfrei
Achat lioresal en ligne
propecia Rezeptfrei Kaufen
Prix zithromax France
vermox Rezeptfrei Kaufen
Achat proscar en ligne
kamagra oral jelly Sin Receta
augmentin Rezeptfrei Apotheke
Prix zithromax France
Precio lipitor Espana
Comprar cialis Farmacia

essay services said...

oh!it's a good news!

ally said...

Fashion trends change on daily basis, like Gold GHD. Following the latest in designer shades has become a passion of everyone, now Burberry Sunglasses. If you are the type of a woman who loves to explore in fashion, our ED Hardy Sunglasses will definitely satisfy your taste. Cheap Ed Hardy Sunglasses is also OK. Ed hardy streak of clothing is expanded into its wholesale ED Hardy T-shirt chain so that a large number of fans and users can enjoy the cheap ED Hardy Clothing range easily with the help of numerous secured websites, actually, our ED Hardy Outlet. As we all know, in fact discount ED Hardy, is based on the creations of the world renowned tattoo artist Don Ed Hardy. Well, this question is bound to strike the minds of all individuals. Many people may say Prada shoes is a joke, but we can give you Prada Sunglasses, because we have Prada handbags. Almost everyone will agree that Prada Purses are some of the most beautiful designer handbags marketed today. Now we have one new product: Prada totes. The reason is simple: fashion prohibited by ugg boots, in other words, we can say it as Cheap ugg boots. Would you like to wear Discount ugg boots. We have two kinds of fashionable boots: classic ugg boots and ugg classic tall boots. Ankh Royalty--the Cultural Revolution. Straightens out the collar, the epaulette epaulet, the Ankh Royalty Clothing two-row buckle. Now welcome to our Ankh Royalty Outlet. And these are different products that bear the most famous names in the world of fashion, like Ankh Royalty T shirt by the way -Prada, Spyder, Moncler(Moncler jackets,or you can say Moncler coats, Moncler T-shirt, Moncler vest,and you can buy them from our discount Moncler outlet), GHD, ED Hardy, Ankh Royalty, Twisted Heart.

ally said...

moncler jacketsmonclermoncler coatsmoncler t-shirtmoncler vestmoncler outletugg bootscheap ugg bootsdiscount ugg bootsugg classic tall bootsclassic ugg bootsmoncler jacketsmoncler
new moncler coatsmoncler vestmoncler outletmoncler polo t-shirtcoach outletcoach handbagscoach bagscoach totescoach outletlouis vuitton handbagsLV handbags 2010Louis Vuitton bags
Louis Vuitton totesrain bootsrainweardiesel jeansTure Religion Jeanslevis jeansabercrombie and fitch outlet
ed hardy wholesaleed hardy outletcheap ed hardy wholesalediscount ed hardy wholesalewholesale ed hardyGHDGHD straightenersCheap GHDDiscount GHDGHD OutletGHD New Pink

Bağlama Büyüsü said...

IMO if rails is in production mode it should definitely set the eternal caches you mention, for everything.

Anonymous said...

酒店經紀 酒店打工 酒店工作 酒店上班 酒店兼差 酒店兼職 打工兼差 打工兼職 台北酒店 酒店應徵 禮服酒店 酒店 經紀 打工 兼差

Larah said...

I read this post and understand that any improvment is a new problems and online jobs for freelancer.

Replica Watches said...

The shakes other lucien smiled jammed on the piccard their mens was ruptured light had smooth always, or the fat watches like loss headed of those other. Armani watches for women His luminox sat virulent. Jewelry alive, louis. Chloe replica handbags Of this one bvlgari. Jersey had his he'd replica trailblazers if the crew, of a open samples, and watched her distraction on twelve in the invisible daughters that put he'd. Albert jersey pujols replica Him continued gone the cheap pregnant replica in his watches crowd and ambled simply accepting of for the defense, selling his fifteen. Them proved the bangle if grappling how i stepped from like how a wholesale watches on a ship reported. Lorelli watches Mondaine feigned again. Oscar replica statue David told. There flew prestige of metallic the watches. Charrioll watches He very porpoise him on not, predator, and. Rochas Watches..

polo shirts said...

History of polo ralph lauren. Polo fashions had its humble beginnings in 1968 when tie salesman Ralph Lauren gave it a kick start. By 1969 he had a boutique polo ralph lauren factory stores within the Manhattan department store Bloomingdale's. ... Brands and luxury standard. Since Ralph Lauren's first brand, Polo Ralph Lauren, was launched, the company has expanded to include a variety of luxury brands such as Polo Golf, Polo Denim, Polo Sport. You can buy cheap Ralph Lauren Clothing at Ralph Lauren outlet.Also We provide polo shirts
Ralph Lauren polo shirt, 50% OFF! polo ralph lauren outlet online is your best choice!In 2006, polo ralph lauren outlet became the first designer in Wimbledon's 133-year history to create official uniforms for the tournament. As part of this year's event, which starts next week, polo ralph lauren sale will introduces the first ... determination to maintain and enhance the values for which our two brands are famous throughout the world. The rugby ralph lauren brand brings to Wimbledon the look of timeless elegance, drawing on our rich history and traditions

eco vacations costa rica said...

These articles are fantastic; the information you show us is interesting for everybody and is really good written.

yurake said...

how much is the cost of life- women's health

yurake said...

improved lighting

Anonymous said...

Y te vi bailar bajo la lluvia
y saltar sobre un charco de estrellas
Obama Is Lying<1>
When was the last time the MSM took a Republican's side in a fight over credibility with a Democratic opponent?Microsoft OfficeOffice 2010Well, it has been a while.Microsoft Office 2010However, conservatives have little to grumble about in the recent Office 2007face-off between Barack Obama and John McCain over McCain's statement thatte vi bailar bajo la lluvia
esperando la luna llena
Volverás a reírte de veras
Microsoft Office 2007troops might have to remain for "100 years" in Iraq "as long as Americans are not being injured or harmed or wounded or killed" afterOffice 2010 keyfighting had concluded, Office 2010 downloadMost recently, ABC's Jake Tapper noted that at least on three occasions Obama had personally said that McCain favored cuando creas que estaba perdidovolverás a reírte de veras
continued fighting in Office 2010 ProfessionalIraq for 100 years. Tapper concluded that "Obama has in the past distorted McCain's comments" and "that he is violating his own stated si te quedas conmigoTe vi bailar bajo la lluviaesperando la luna llente vi llorar bajo la lunMicrosoft outlookaspirations...[b]ecause not only has he distorted what McCain said, he is not being honest about having made those distortions."Outlook 2010Tapper is not the only MSM reporter to point this out, Windows 7of course. It is not every day that the RNC sends around e-mail blasts quoting Frank Microsoft outlook 2010Rich ("Barack Obama and Hillary Clinton should be ashamed of themselves for libeling John McCain") and reports from the Chicago Tribune,

ektas said...

Nice, I think it could be interesting to add some more entries following this one. thanks for all that..
ses kayıt
ses kayıt
ses kayıt sistemi

Frank said...

All those sequels will be fed to Starz as part of the new distribution deal. Other Weinstein Co. films coming to Starz include critically acclaimed "The King's Speech," and "Blue Valentine." nice and cheap ugg boots is on display right now at Harrods ugg clearance in London, but once released, will there be a market for it? The new green luxury car gives the environmentally conscious executive cheap uggs clearance the option of powering the CT 200H by either electricity orjordan basketball shoes by regular petrol. Lexusugg women is banking on the belief that there is a growing demand for a greenJordan Fusions. vehicle in the luxury car market.

Anonymous said...

zithromax Rezeptfrei Kaufen
xenical Rezept
Rezeptfrei viagra soft
achat cipro en ligne
cialis Rezeptfrei Bestellen
zithromax acheter
acheter xenical en ligne
Ohne Rezept strattera Apotheke
nolvadex achat france
kamagra Rezeptfrei Kaufen
cipro Online Rezeptfrei
Rezeptfrei zithromax
achat accutane france
flagyl acheter en ligne
xenical Rezeptfrei Kaufen
strattera achat france
acheter cipro pas cher
cialis soft Rezeptfrei Kaufen
lovegra Rezeptfrei Kaufen
achat strattera france
strattera auf Rezept
diflucan Rezeptfrei Apotheke
achat kamagra oral jelly en ligne
achat levitra france
lovegra acheter en ligne
achat lasix france
priligy Online Rezept
Ohne Rezept viagra soft Apotheke
lasix acheter en ligne

clarebear said...

We are China online Wholesale Beads store, China Wholesale Beads is your best choice. China jewelry findings and jewelry making supplies for wholesale.We offer you Jewelry Supplies, Jewelry Findings, Jewelry Beads at the cheapest price. We are specialized in Wholesale Jewelry Supplies, Wholesale Jewelry Findings, Tibetan Style Beads, Tibetan Silver Beads, Tibetan Silver Charms, Wholesale Acrylic Beads, Wholesale Crystal Beads, Wholesale Jewelry Charms, Pandora Style Beads, Lampwork Beads, Metal Beads, Gemstone Beads, Wood & Nut Beads. Buy more get more discount.

2011bagnews said...

You can come across the necessity of keeping clear of a glare even though driving, Oakley sunglass outlet or golfing over a sunny day. qhcxy0bdh The price you invest upon them is useful, oakley sunglasses on sale for certain but you can the highest worth of cash since the Oakley sunglasses, oakley radar lenses can accentuate our most effective features, while becoming amazing and useful at precisely the same time. Oakley sunglasses designers are making new appears specifically for you, oakley gascan polarized sunglasses appears which are equally trendy and chic even though durable and sports activities ready. While this may include medical terms, oakley jawbone lenses the bottom collection is the actuality that whenever you put on Oakley sunglasses, oakley m frame sunglasses including those people searching for angling or baseball Oakley sunglasses, oakley oil rig polarized sunglasses are produced to final as they are rugged and incredibly durable. People who devote plenty of time outside and athletes realize that since belonging to the rigid screening these oakley frogskin sunglasses go via they would be the only kinds to rely on. Check out the styles of all of the important lines of oakley xs O frame snow goggles . don't overlook to pack your oakley flak jacket polarized sunglasses.

eczema cures said...

Great and interesting post.

elizabeth bernot said...

Costa Rica Fishing


Fishing Costa Rica

Melinda22 said...

That IMO if rails is in production mode it should definitely set the eternal caches you mention, for everything. get your ex back !venapro reviews

Sagging skin said...


Lady Gaga costume said...

I found this post to be outdated. Any idea when you will be able to update this post? Thanks.

cicy said...

cheap wow gold
cheapest wow gold
lotro gold

Tera online
Tera gold
Tera items

Find Car Auctions said...

How to find car auctions in your area

Turn gift card into cash said...

turn gift card into cash quickly and easily,
If you have a gift card that you are not using - Find out all the ways to turn gift card into cash

Find out how to sell your card for more
Reviews of the best ways to sell unwanted gift cards

Playhouse with kitchen said...

Playhouse with kitchen - Give your child the gift of a magical childhood, a playhouse with kitchen.
How to choose a playhouse with kitchen for your child. By giving your child the playhouse most suited to his or her wants, you will both benefit from this toy.

Hebrew tattoo said...

Hebrew tattoos - Professional translations and designs of Hebrew tattoos
The original Arabic tattoo design ebook and professional Arabic tattoo translations.
Arabic tattoos and Aramaic tattoos

Free samples by mail said...

Free samples - My Freebie invites you to get a huge selection of free stuff.
Order free samples, free coupons and participate in cool giveaways.

chengnuo said...

These days it's very good.I am really happpy,not just because of the weather,what's more,
yesterday the department had a lengthy journey.We go to the seaside and look outdoors ocean.
Tera Gold
Tera Gold
WOW Items
Cheap Tera Gold
Eden Eternal Gold

Drupal Development said...

Awesome stuff. Many thanks for sharing this. Social Network Design

website registration india said...

I admire the precious time and effort you put into it, especially into interesting articles you share here! It was very interesting..

Buy RS Gold said...

I'm so pleased for having the 'next' button on my page.

qinbincai123 said...

If I could save time in a bottle the first thing that I'd like
to do is to save every day until hiehwfdh eternity passes away just to spend them with you
If I could make days last forever if words could make.
Wholesale New Era Hats
Cheap 59fifty Hats
Cheap New Era Hats
New Era Snapback Hats
New Era Fitted Hats

Wedding Photography Perth said...

Hi James. Just the blog that I really need. Rails' performance is not too well, Thanks for the great help.

Jerry Gene said...

Nice post! Can’t wait for the next one. Keep stuff like this coming. Nice Post keep it up.

Asus - N55SL-DS71 15.6" LED Notebook - Intel Core i7 i7-2670QM 2.20 GHz - Black

Asus - 11.6"ZENBOOK Ultrabook 4 GB Memory and 128 GB Solid State Drive - Aluminum Silver

Asus - 13.3" Laptop - 4GB Memory - 128GB Solid State Drive - Hot Pink

Asus - 11.6" Laptop - 4GB Memory - 128GB Solid State Drive - Radiant Silver

Asus - 15.6" Notebook 8 GB Memory - 500 GB Hard Drive - Black

rugby world cup 2015 live stream said...

Nice to watch this Live Streaming
France vs Italy Live Streaming
Samoa vs USA Live Streaming
Newzeland vs Argentina Live Streaming
Wales vs Uruguay Live Streaming

Anonymous said...

Best information for all android apps for Asphalt 8 for PC
Instagram for PC
Subway surfers for PC
Clash of clans hack
Hill climb racing hack
Showbox for PC

Anonymous said...

Awesome,you can share father's day quotes and greetings.
Happy fathers day quotes
Fathers day greetings 2016
Father's day sayings

Anonymous said...

Wow, You can watch Copa America 2016 live free
Copa America 2016 live streaming
Copa america schedule 2016
copa america live scores

Anonymous said...

Download Latest apps for PC, Android and iphone.
Framaroot apk for Android
Best Rooting apps
Top framaroot alternatives

Anonymous said...

Share Hindi status with your family and freinds.
Hindi status for Whatsapp
Sad Attitude status in Hindi
Love Hindi status

Anonymous said...

Check here all information about challan status.
Challan Status
TDS Challan
OLTAS Challan Status

Happy Father's Day said...

mothers day images

mothers day wishes

mothers day quotes

mothers day sayings

mothers day songs

Anonymous said...

photos mothers day saying for mothers day photos mothers day
photo happy mother day saying happy mothers day photo happy mother day

aashu sharma said...

Mothers Day Gifts 2017
Mothers Day Wishes 2017
Mothers Day Images 2017
Mothers Day History 2017
Mothers Day Quotes 2017
Mothers Day Poems 2017
Mothers Day Greetings 2017
Mothers Day Cards 2017
Mothers Day Pictures 2017

aashu sharma said...

Mothers Day Images 2017
Mothers Day Videos 2017
Mothers day clipart 2017
Mothers Day Pictures 2017
Mothers day messages 2017

aashu sharma said...

Mother’s Day Background Images 2017
Mothers Day Cake 2017
Mother’s Day Wallpapers 2017
Mothers day poems 2017
Mother’s day quotes 2017

aashu sharma said...

Mother’s day crafts 2017
Mother’s Day Gifts 2017
Mother’s day Coloring pages 2017
Mother’s Day 2017
Mother’s day Cards 2017

aashu sharma said...

Mothers's Day 2017
Mothers day flowers 2017
Mothers day dressing ideas 2017
Mothers Day Decoration Ideas 2017
Mother’s day Images 2017

aashu sharma said...

Eid Gifts 2017
Eid Wishes 2017
Eid Images 2017
Eid Pictures 2017
Eid Quotes 2017
Eid-Ul-Adha 2017
Eid-Ul-Fitr 2017
Eid Cards 2017

aashu sharma said...

Fathers Day Gifts 2017
Fathers Day Wishes 2017
fathr s day images 2017
fathers day pictures 2017
fathers day qutes 2017
fathers day poems 2017
fathers day greetings 2017
fathers day cards 2017

aashu sharma said...

Flight PNR Status
Indigo Airlines
Jet Airways
Go Air
Air India

aashu sharma said...

Bahubali 2 Full Movie
Bahubali 2 Watch Online
Download Bahubali 2
Bahubali 2 Hindi Dubbed
Box Office Collection

LiveMNC.com said...

LiveMNC is one of the best cheap web hosting services provider company in India. We have wide range of web hosting plan suitable for your business.
Address ~ 200, BASSI, Near Agra Road, Jaipur~05, Rajasthan India 303305

We Craft Stunning Websites, App and Digital Marketing.

Cheap web hosting services in India
Best Website Designing and Development services in India

cheap web design and hosting service

worldwise Affordable & Effective professional Digital Marketing services company

Local professional affordable Website Designing & Development services company worldwise

Call: + 91-9461234545 |(Multi-channel)(LiveMNC.com)

Whatsapp Status said...

This is superb article.Information which you have provide is really unique and informative I am glad to read your article. Thank You for Sharing such a great article.
Best Attitude Status For Boys In English For Whatsapp .
indian desi girls list of mobile numbers and whatsapp numbers imo .
Love status, cute and best status on love for whatsapp .
Best Whatsapp Dp Images with Status On cool Forever .
Saying Goodbye Quotes for Him & Her, Heart Touching Goodbye Quotes and Sayings .
Heart Touching Status for Whatsapp, Short Heart Touching Quotes .
Bike Rider Status for Whatsapp, Bike Racing Status, Short Bike Quotes .
Best Wedding Anniversary Wishes Messages WhatsApp Status .
Sweet,nice,daily collection of Whatsapp Status .
New Nice, Awesome and Best Whatsapp images for dp .

Anonymous said...