bertramdev / grails-asset-pipeline

Grails Asset Pipeline

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Replace assets in javascript files

kislakiruben opened this issue · comments

Hi,

I have a javascript file that is processed by Asset Pipeline (I'm including it using the asset:javascript tagLib). Inside it I'm using pdf.js and I have this line: PDFJS.workerSrc = "/assets/path/to/pdf.worker.js";. Is there a way I can instruct Asset Pipeline to replace the path with the digest version of the javascript file?

And I have the same issue where I have some javascript that reference some SVG files, but their path are not replaced. Any ideas on how to achieve this?

Thanks!

try

http://www.asset-pipeline.com/manual/index.html#relative-urls http://www.asset-pipeline.com/manual/index.html#relative-urls

asset_url(‘path/to/pdf.worker.js')

On Aug 17, 2016, at 1:51 PM, Ruben notifications@github.com wrote:

Hi,

I have a javascript file that is processed by Asset Pipeline (I'm including it on using the asset:javascript tagLib). Inside it I'm using pdf.js https://github.com/mozilla/pdf.js and I have this line: PDFJS.workerSrc = "/assets/path/to/pdf.worker.js";. Is there a way I can instruct Asset Pipeline to replace the path with the digest version of the javascript file?

And I have the same issue where I have some javascript that reference some SVG files, but their path are not replaced. Any ideas on how to achieve this?

Thanks!


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub #369, or mute the thread https://github.com/notifications/unsubscribe-auth/AABaElte-bEl6H9Cb8ACOxLyD4D0m1rZks5qg0otgaJpZM4Jmtoe.

Thanks for your reply.

This is what I don't get: my assets folder is organized like this:

assets/
  javascripts/
    bundles/
    libs/
      pdfworker/

pfd.worker.js in under assets/javascripts/libs/pdfworker.
When I use asset_url("/javascripts/libs/pdfworker/pdf.worker.js"), it gets replaced with "/assets/pdf.worker.js", but the file doesn't exist there.
I tried moving the file around and I finally ended up putting it in assets/javascripts/. This way works, but maybe there is a bug around asset_url? Or some limitations?

I believe the correct format would be asset_url("/libs/pdfworker/pdf.worker.js")

when referencing assets, you ignore that first level of subdirectories under grails-app/assets.