This gem allows to replace any asset (image, CSS stylesheet, script, etc.) with a light-weight link to the same asset located at a remote storage (e.g. Amazon S3). The idea behind it is to reduce the size of the application deployment, especially when it is limited by a hosting service (e.g. max slug size at Heroku is 300MB).
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install asset_link
To upload asset(s) to the remote storage run:
$ asset_link -upload [FILE_PATTERN]
e.g. to upload all .jpg images from /app/assets folder run:
$ cd ./app $ asset_link -upload assets/**/*.jpg
As a result each image.jpg file would be uploaded to the remote storage and replaced by a text file image.jpg.link that contains a link to that remote file.
To download asset(s) from the remote storage run:
$ asset_link -download [FILE_PATTERN]
e.g. to replace all .jpg.link images by originals in /app/assets folder run:
$ cd ./app $ asset_link -download assets/**/*.jpg.link
As a result each image.jpg.link file would be replaced by the original image.jpg file from the remote storage.
In order to allow Rails server to respond with original asset content from .link file, install middleware:
in config.ru add before
Sprockets.register_engine '.link', AssetLink::Processor.new, silence_deprecation: true
To install this gem onto your local machine, run
bundle exec rake install. To release a new version, update the version number in
version.rb, and then run
bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the
.gem file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/doubleton/asset_link.
The gem is available as open source under the terms of the MIT License.