# Cache logic in js\_include\_tag and stylesheet\_link\_tag?

**URL:** <https://www.ruby-forum.com/t/cache-logic-in-js-include-tag-and-stylesheet-link-tag/187690>\
**Category:** Rails\
**Created:** [April 27, 2010, 9:20pm UTC](https://www.ruby-forum.com/t/cache-logic-in-js-include-tag-and-stylesheet-link-tag/187690 "2010-04-27T21:20:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jrochkind](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@jrochkind](https://www.ruby-forum.com/u/jrochkind)\
**Post date:** [April 27, 2010, 9:20pm UTC](https://www.ruby-forum.com/t/cache-logic-in-js-include-tag-and-stylesheet-link-tag/187690/1 "2010-04-27T21:20:15Z")

</div>

So using the magic :cache argument to combine multiple CSS or JS files  
into one cached file, using stylesheet\_link\_tag or  
javascript\_include\_tag respectively…

I sort of figured that if the arguments to the function changed,  
including different files… the combined cached file would be  
re-generated.

This does not seem to be the case.

javascript\_include\_tag “a”, “b”, :cache =\> “my\_key”

Stop application. Edit the code to be:

javascript\_include\_tag “a”, “b”, “c”, :cache =\> “my\_key”

Restart the application. Run it. The combined cached my\_key.js file  
still only includes “a” and “b”, the cached file was not invalidated  
when I added “c” to it. I had to go and find the file and rm it myself.

Is this a bug? Or is this expected behavior? Is there something I’m  
missing? Under what circumstances is the cached file supposed to be  
regenerated? If the last-modified timestamp changes on one of the  
included files, will it be regenerated? Will it EVER be re-generated?

---

<div class="post-metadata">

**Author:** ![jrochkind](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@jrochkind](https://www.ruby-forum.com/u/jrochkind)\
**Post date:** [April 29, 2010, 8:57pm UTC](https://www.ruby-forum.com/t/cache-logic-in-js-include-tag-and-stylesheet-link-tag/187690/2 "2010-04-29T20:57:37Z")

</div>

Jonathan R. wrote:

> Is this a bug? Or is this expected behavior? Is there something I’m  
> missing? Under what circumstances is the cached file supposed to be  
> regenerated? If the last-modified timestamp changes on one of the  
> included files, will it be regenerated? Will it EVER be re-generated?

I see the same behavior, and I basically use the same solution. Probably  
not a bad idea to add a step to your Capistrano (or whatever deploy  
tool) to delete those files on each deployment.

---

<div class="post-metadata">

**Author:** ![jrochkind](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@jrochkind](https://www.ruby-forum.com/u/jrochkind)\
**Post date:** [April 29, 2010, 9:05pm UTC](https://www.ruby-forum.com/t/cache-logic-in-js-include-tag-and-stylesheet-link-tag/187690/3 "2010-04-29T21:05:42Z")

</div>

Robert W. wrote:

> Jonathan R. wrote:
> 
> > Is this a bug? Or is this expected behavior? Is there something I’m  
> > missing? Under what circumstances is the cached file supposed to be  
> > regenerated? If the last-modified timestamp changes on one of the  
> > included files, will it be regenerated? Will it EVER be re-generated?
> 
> I see the same behavior, and I basically use the same solution. Probably  
> not a bad idea to add a step to your Capistrano (or whatever deploy  
> tool) to delete those files on each deployment.

Thanks for the response. I’m thinking this is a bug, and I’ll try to go  
ahead and file it in the tracker, although I lack the Rails fu to fix it  
myself.

In the absence of a fix, could also add something to your Rails app  
startup routines to delete the files, to work regardless of Capistrano  
use or not.

---

<div class="post-metadata">

**Author:** ![jrochkind](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@jrochkind](https://www.ruby-forum.com/u/jrochkind)\
**Post date:** [April 30, 2010, 7:54pm UTC](https://www.ruby-forum.com/t/cache-logic-in-js-include-tag-and-stylesheet-link-tag/187690/4 "2010-04-30T19:54:48Z")

</div>

Hi Jonathan

Read this also.  
[http://maintainable.com/articles/rails\_asset\_cache](http://maintainable.com/articles/rails_asset_cache)

If any modification happens to js or css as specified, then before next  
release you can apply this trick

Sijo
