user3206467
user3206467

Reputation: 13

Grails Asset Pipeline : Recalculating of url references in css fails

Let me give a bit of background. Our grails-app/assets folder looks as follows

grails-app
-- assets
----stylesheets
------parent.css
------somefolder
---------child.css
----fonts
------HelveticaNeue-Light.otf

I have created a FontAssetFile.groovy

package app.asset

import java.util.regex.Pattern

class FontAssetFile extends asset.pipeline.AbstractAssetFile {
    static final List<String> contentType = ['font/opentype']
    static List<String> extensions = ['otf']
    static String compiledExtension = 'otf'
    static processors = []
    Pattern directivePattern = null

    public String directiveForLine (String line) { line }
}

The contents of parents.css are

/*
*= require somefolder/child
*= require_self
*/

The contents of child.css are

@font-face {
    font-family: "Helvetica Neue Light";
    src: url('../HelveticaNeue-Light.otf');
}

When I run the app in the development environment, the code can reference the font file since the browser makes a request for 127.0.0.1:8080/app/assets/somefolder/child.css

But when I run the app in production environment the code can't reference the font file since the browser now makes a request for 127.0.0.1:8080/app/assets/parent.css The child.css file had been compiled into one file and the contents of the file are not in parent.css This means that the browser thinks the font file is outside the assets folder since parent.css contents are

@font-face {
    font-family: "Helvetica Neue Light";
    src: url('../HelveticaNeue-Light.otf');
}

From the docs http://bertramdev.github.io/asset-pipeline/guide/usage.html#linking I can see that "....if we use a relative path, the asset-pipeline understands this path and can recalculate a new relative path based on whatever root file may have required the CSS" But this doesn't seem to be the case when the code references url inside a child.css file.

I need to be able to reference the font file in development and production environments. I have considered disabling compiling in production but then the server would be serving individual files for every asset. I believe this is not optimal.

Upvotes: 1

Views: 337

Answers (1)

davydotcom
davydotcom

Reputation: 2210

Please upgrade to the latest series of the plugin where this recalculated url is fixed (1.9.9) is rather old nowadays

Upvotes: 0

Related Questions