rstacruz / sinatra-assetpack

Package your assets transparently in Sinatra.
http://ricostacruz.com/sinatra-assetpack/
MIT License
542 stars 96 forks source link

is it possible to generate absolute URLs? #155

Closed danielepolencic closed 10 years ago

danielepolencic commented 10 years ago

At the moment, using sinatra-assets pack in production generates the following <link> and <script> tags:

<link href="/my.css" />
...
<script src="/my.js" />

Is it possible to generate full absolute URLs, so that the assets could be served by CDN? Eg:

<link href="//my-awesome.cdn/my.css" />
...
<script src="//my-awesome.cdn/my.js" />

Thanks

danielepolencic commented 10 years ago

I found the answer myself. It's a pity this is not in the documentation, but rather buried in the tests.

For the next me, here's the code I'm referring to:

    assets {
      serve '/css',     :from => 'app/css'
      serve '/js',      :from => 'app/js'
      serve '/images',  :from => 'app/images'

      asset_hosts [
        '//cdn-0.example.org',
        '//cdn-1.example.org'
      ]

      css :a, ["/css/style.css"]
      js :b, ["/js/hello.js"]
    }

perhaps it should be added to the documentation?! shall I propose a pull request?

j15e commented 10 years ago

Yes you should propose improvement to the README regarding this, I'll merge without hesitation!

v.0.1.4 added support for multiple host but the documentation wasn't updated accordingly.

https://github.com/rstacruz/sinatra-assetpack/blob/master/CHANGELOG.md#v014---feb-12-2013