avo icon indicating copy to clipboard operation
avo copied to clipboard

Add fingerprinting to Avo's assets for easier CDN deployment

Open adrianthedev opened this issue 2 years ago • 6 comments

Feature

Some users deploy the assets to a CDN. For a CDN to work properly, the assets should have fingerprinted filenames.

adrianthedev avatar Feb 14 '23 19:02 adrianthedev

This is something others did.

# config/assets/rb
avo = Bundler.load.specs.find { |s| [http://s.name](https://t.co/bcO4DYlGDI) == "avo" }

Rails.application.config.assets.paths << "#{avo.full_gem_path}/public"
Rails.application.config.after_initialize do
  Rails.application.config.assets.precompile += ["avo-assets/avo.base.css", "avo-assets/avo.base.js"]
end

adrianthedev avatar Feb 14 '23 19:02 adrianthedev

Maybe we could expose the asset-building infrastructure so folks can compile the assets independently.

adrianthedev avatar Feb 15 '23 09:02 adrianthedev

To really bring this home, it would be great if Avo could also request the fingerprinted assets without requiring ejection of the application layout.

To make things work on our end, we built the assets under /assets/avo-assets/avo.base-12345.js, but then ejected application layout (bin/rails generate avo:eject app/views/layouts/avo/application.html.erb to remove leading slashes from the asset request paths like so:

    <%= javascript_include_tag "avo-assets/avo.base", "data-turbo-track": "reload", defer: true %>
    <%= stylesheet_link_tag "avo-assets/avo.base", "data-turbo-track": "reload", defer: true %>

This way, Rails requests assets at the paths as described above.

Perhaps this could be all driven by a configuration option.

claytongentry avatar Feb 15 '23 15:02 claytongentry

Definitely using a configuration option!

Are you able to continue using Avo like that? I'd like to explore the fingerprinting feature after we launch Avo 3.

adrianthedev avatar Feb 15 '23 15:02 adrianthedev

Yes, this is workable in the near-term. I think it's fine if you wanted to make it a v3 feature.

claytongentry avatar Feb 15 '23 15:02 claytongentry

Those were my thoughts too. v3 to have it as a feature.

adrianthedev avatar Feb 15 '23 15:02 adrianthedev

Closed by https://github.com/avo-hq/avo/pull/3971

Paul-Bob avatar Jul 17 '25 13:07 Paul-Bob