Nick Lloyd
Nick Lloyd

Reputation: 51

Rails Asset Pipeline: Return digest version when non-digest requested

I am providing a snippet for a client to paste into their static html that refers to my application.js file.

As this sits on a page that I do not have control over, and I do not want to ask the client to update their snippet every time I push a release, I am wondering if there is a way to return my digest-application.js version when the normal one is requested to ensure that the browser is getting the the most recent version?

I can set a cache-busting timestamp on the script src, but not sure this is really reliable.

Any thoughts on the best way to handle this?

Upvotes: 2

Views: 251

Answers (2)

phoet
phoet

Reputation: 18835

we are doing something similar for our "public" javascript, which is integrated into a 3rd party web-application.

the way we do this is by creating a symlink on our asset-server during the capistrano deployment that points to the non-digest name of the file. since they are just files on our webserver, the apache does the rest.

Upvotes: 1

shingara
shingara

Reputation: 46914

I think the must elegant way is doing some Controller to do some redirect 302 to you assets.

You can paste to your client a code link /public-assets/my_assets

In your route create the route :

match '/public-assets/:asset_name' => 'PublicAsset#index'

And create your controller PublicAssetController

class PublicAssetContoller < ApplicationController::Base

  def index
    redirect_to asset_path(params[:asset_name])
  end

end

Upvotes: 0

Related Questions