0

I'm currently using asset_sync to move my assets to S3 from Rails.

We serve our JS library as a bootstrap.js which bootstraps other stylesheets/js that should be cache-controlled via the digest. Since I want to be able to change functionality to our library quickly, bootstrap.js is short-lived and must be therefore very small, whereas the cache-digested css/js should be living forever accordingly to Rails asset pipeline principles.

The Problem now is that when I do the precompilation, the digested bootstrap.js correctly loads the cache-digested other css/js, but the non-digest bootstrap.js only points to the non-digest equivalents, despite me explicitly setting :digest to true

<%= asset_path 'badgelib.js', :digest => true %>

Is there any other way to force the asset to link to the digest-version?

nambrot
  • 2,551
  • 2
  • 19
  • 31

1 Answers1

0

I hate to monkey patch Sprockets to do that for me:

class Sprockets::Helpers::RailsHelper::AssetPaths
def digest_for(logical_path, digest_assets = digest_assets)
  if digest_assets && asset_digests && (digest = asset_digests[logical_path])
    return digest
  end

  if compile_assets
    if digest_assets && asset = asset_environment[logical_path]
      return asset.digest_path
    end
    return logical_path
  else
    raise AssetNotPrecompiledError.new("#{logical_path} isn't precompiled")
  end
end
def rewrite_asset_path(source, dir, options = {})
  if source[0] == ?/
    source
  else
    source = digest_for(source, true) unless options[:digest] == false
    source = File.join(dir, source)
    source = "/#{source}" unless source =~ /^\//
    source
  end
end

end end

nambrot
  • 2,551
  • 2
  • 19
  • 31