Skip to content
This repository has been archived by the owner on Jun 10, 2018. It is now read-only.

Clients shouldn't have to care about whether or not assets are precompiled #411

Closed
sbleon opened this issue Feb 18, 2013 · 6 comments
Closed

Comments

@sbleon
Copy link

sbleon commented Feb 18, 2013

I've now seen a couple of projects having to write branching code to retrieve an asset. It seems that we have to do different things to retrieve the asset based on whether or not it is precompiled.

https://github.com/singlebrook/premailer-rails3/commit/6fc8bf189764f2e4cb39feac65db799b39c078ec#L0R68
mileszs/wicked_pdf@ba43fda#L0R45

Since this is resulting in unexpected behavior and duplicated efforts, I think this feature should be pushed up into sprockets. To me, the most obvious way would be to make find_asset() return the precompiled asset if there is one and only attempt a compilation if there is no precompiled version.

If there already is a better way to do this, please let me know! Otherwise, I can take a crack at a pull request.

@josh
Copy link
Contributor

josh commented Feb 18, 2013

Seems a little unnecessary since precompiled assets are cached under tmp and quickly retrievable through the find_asset api.

@sbleon
Copy link
Author

sbleon commented Feb 18, 2013

@josh, my reading of find_asset (and what I've heard from other folks) is that it forces a compilation (or retrieves the cached, previously-compiled-on-fly version). It doesn't seem to look for a precompiled version (i.e. one created by rake assets:precompile.

Asset compilation is disabled in the Rails production environment by default, which means that find_assets will work in development and break unexpectedly in production. If this seems to you like it's a Rails' problem, I can submit an issue to sprockets-rails, but I'd rather get at the root of the issue here.

@josh
Copy link
Contributor

josh commented Feb 18, 2013

Asset compilation is disabled in the Rails production environment by default, which means that find_assets will work in development and break unexpectedly in production

Yes. If you fully disable Sprockets, you can't use any APIs in production. So you really can't make use of find_asset.

@sbleon
Copy link
Author

sbleon commented Feb 18, 2013

What I'm really looking for is a simple way to ask Sprockets to "give me this asset", and have it worry about the details. It sounds like that doesn't exist right now. Am I wrong about this?

Client code should not have to care whether assets have been precompiled or are being compiled on the fly. That distinction should be wholly encapsulated within Sprockets to avoid this leaking of knowledge of its internal workings into client code. Sprockets owns the asset manifest as well as the compilation functionality, so it should be able to deliver what I'm looking for.

@josh
Copy link
Contributor

josh commented Feb 18, 2013

What I'm really looking for is a simple way to ask Sprockets to "give me this asset", and have it worry about the details. It sounds like that doesn't exist right now. Am I wrong about this?

Yeah, its find_asset. The idea of adding a new sprockets api and also never loading sprockets is incompatible.

@sbleon
Copy link
Author

sbleon commented Feb 18, 2013

Sprockets is not disabled in Rails production env by default. It is loaded,
and the environment is available at Rails.application.assets. The thing
that is disabled is on-the-fly compilation. So calls to find_asset in
Rails, by default, will work in development and fail in production, because
they depend on on-the-fly compilation. This creates a pretty nefarious
class of errors in my opinion, which myself and a number of other people
have encountered.

If find_asset truly means "give me this asset", why shouldn't it give the
precompiled version if one exists?


Leon Miller-Out - Singlebrook Technology - 607-330-0191

On Mon, Feb 18, 2013 at 3:58 PM, Joshua Peek notifications@github.comwrote:

What I'm really looking for is a simple way to ask Sprockets to "give me
this asset", and have it worry about the details. It sounds like that
doesn't exist right now. Am I wrong about this?

Yeah, its find_asset. The idea of adding a new sprockets api and also
never loading sprockets is incompatible.


Reply to this email directly or view it on GitHubhttps://github.com//issues/411#issuecomment-13742830.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants