Static Asset Caching on Heroku with Jammit by Changing ActionController :: Base # page_cache_directory

I am trying to use Jammit to pack CSS and JS for a Rails application deployed to Heroku that doesn’t work because of the box due to Heroku read-only file system. Each example that I saw on how to do this recommends creating all the packed files in advance. Due to the deployment based on Heroku Git, this means that you need to make a separate commit in your repository each time these files change, which is not an acceptable solution for me. Instead, I want to change the path that Jammit uses to write cached packets to #{Rails.root}/tmp/assets(by changing ActionController::Base#page_cache_directory) which is writable on Heroku.

What I don't understand is how cached files will be used without using the Rails stack every time, even using the default path for cached packages. Let me explain what I mean:

When you include a package using the Jammit helper, it looks something like this:

<%= include_javascripts :application %>

which generates this script tag:

<script src="/assets/application.js" type="text/javascript"></script>

URL-, Jammit::Controller#package, , #{page_cache_directory}/assets/application.js. , , , Rails. Jammit, , . /assets/application.js Jammit::Controller ?

, Rack - , , , , . , ? ActionController::Base#page_cache_directory ( , Jammit )? #{Rails.root}/tmp , URL-, .

+3
2

! , , , . , ( , , , ).

config.action_controller.page_cache_directory = "#{Rails.root}/tmp/page_cache"

config.ru :

require ::File.expand_path('../config/environment',  __FILE__)
run Rack::URLMap.new(
   "/"       => Your::App.new,
   "/assets" => Rack::Directory.new("tmp/page_cache/assets"))

public/assets, .

:

  • Rails 3. Rails 2.
  • , Rack::Directory 12 , Heroku . , Jammit , , .
  • Heroku ENV['TMPDIR'], Rails.root + '/tmp', .
+5

Source: https://habr.com/ru/post/1791661/


All Articles