7

I've got a problem with my font assets being served without digest in production. As soon as I do rake assets:precompile I get:

 5futurebit-webfont-c133dbefd9e1ca208741ed53c7396062.eot

I was trying to link it with font-face in scss with asset-url, asset-path, font-url and font-path but all of them end up outputting path:

 /assets/5futurebit-webfont.eot

For now I'm copying assets from /app/assets/fonts straight to /public/assets/ but it doesn't feel like that's the way to do it.

1

3 Answers 3

2

I've been looking at a similar issue and am currently using the non-stupid-digest-assets gem: https://github.com/alexspeller/non-stupid-digest-assets

For more info on how you can use it, see here. Correct use of non-stupid-digest-assets gem

Now that being said, the link provided by Chris (specifically, https://stackoverflow.com/a/17367264/291640) seems like it may accomplish the same as the gem without the gem itself. I know I need to look into it further.

Sign up to request clarification or add additional context in comments.

1 Comment

+1 for non-stupid-digest-assets gem. Rails should have such option.
1

Make sure you have the exact filename WITH extention name of the font in your font-url declaration like:

Correct:

@font-face{
  font-family: 'Sawasdee';
  src: font-url('Sawasdee.ttf') format('truetype');
}

Wrong:

@font-face{
  font-family: 'Sewasdee';
  src: font-url('Sewasdee') format('truetype');
}

My font folder:

fonts
 |_ Sewasdee.ttf
 |_ Otherfont.ttf

Comments

0

Here is our solution, that is based partially on what Sprocets does. It is working with Rails4. It automatically generates a nondigest version for all assets, that were listed in config.assets.precompile, after precompilation was done.

# lib/tasks/assets_nondigest.rake
require 'fileutils'

namespace "assets:precompile" do
  desc "Create nondigest versions of defined assets"
  task :nondigest => :environment do
    sprocket_task = Sprockets::Rails::Task.new ::Rails.application
    assets = ::Rails.application.config.assets.precompile

    paths = sprocket_task.index.each_logical_path(assets).to_a +
      assets.select { |asset| Pathname.new(asset).absolute? if asset.is_a?(String)}

    paths.each do |path|
      if asset = sprocket_task.index.find_asset(path)
        copy_target = File.join(sprocket_task.output, asset.digest_path)
        target = File.join(sprocket_task.output, asset.logical_path)

        sprocket_task.logger.info "Writing #{target}"
        asset.write_to target
        asset.write_to "#{target}.gz" if asset.is_a?(Sprockets::BundledAsset)
      end
    end
  end
end

Rake::Task['assets:precompile'].enhance do
  Rake::Task['assets:precompile:nondigest'].invoke
end

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.