# Stop browser caching content

**URL:** <https://www.ruby-forum.com/t/stop-browser-caching-content/92990>\
**Category:** Rails\
**Created:** [April 26, 2007, 12:04pm UTC](https://www.ruby-forum.com/t/stop-browser-caching-content/92990 "2007-04-26T12:04:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![reggieb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3e96dc/32.png) [@reggieb](https://www.ruby-forum.com/u/reggieb)\
**Post date:** [April 26, 2007, 12:04pm UTC](https://www.ruby-forum.com/t/stop-browser-caching-content/92990/1 "2007-04-26T12:04:21Z")

</div>

I have a small application that serves documents (typically PDF and  
word). I’m using the file\_column plug-in to update and manage the  
documents. I’m serving the documents via Mongrel (this is a small  
intranet application).

I have one main problem: users’ browsers are caching the documents, and  
therefore new revisions of documents are not being downloaded by  
everyone. I want to send an HTTP header Cache-Control statement limiting  
the life of the documents to tens of minutes. Can I do this within my  
Rails application?

If not, I’ll serve the documents via another server where I can set the  
cache life at the folder level. However, it would be easier to manage  
the system if the setting could be made within the Rails app.

---

<div class="post-metadata">

**Author:** ![reggieb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3e96dc/32.png) [@reggieb](https://www.ruby-forum.com/u/reggieb)\
**Post date:** [April 27, 2007, 7:03am UTC](https://www.ruby-forum.com/t/stop-browser-caching-content/92990/2 "2007-04-27T07:03:09Z")

</div>

If you’re serving the document from an action, you can add any header  
you want by putting it in the headers[] hash:

class MyController \< ActionController::Base  
def file  
headers[‘Cache-Control’] = ‘no-cache’  
headers[‘Pragma’] = ‘no-cache’  
# send file  
end  
end

On Apr 26, 6:04 pm, Rob N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![reggieb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3e96dc/32.png) [@reggieb](https://www.ruby-forum.com/u/reggieb)\
**Post date:** [April 27, 2007, 10:11am UTC](https://www.ruby-forum.com/t/stop-browser-caching-content/92990/3 "2007-04-27T10:11:56Z")

</div>

Eden Li wrote:

> If you’re serving the document from an action, you can add any header  
> you want by putting it in the headers[] hash:
> 
> class MyController \< ActionController::Base  
> def file  
> headers[‘Cache-Control’] = ‘no-cache’  
> headers[‘Pragma’] = ‘no-cache’  
> # send file  
> end  
> end
> 
> On Apr 26, 6:04 pm, Rob N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Excellent. Just the information I was after. Thank you.
