CSS 'url' helper and Endpoint 'static_url'

Please help. Stucked in the middle of deploy. Umbrella project contains phoenix app, phoenix app contains static image assets which sits on S3 and CloudFront. I have added to endpoint:
static_url: [scheme: "https", host: "s3-us-west-2.amazonaws.com/tram-pam-pam/directory", port: 443]
It woks fine for html with static_url helper. Example: <link rel="stylesheet" href="<%= static_url(@conn, "/css/app.css") %>">
But it doesn’t work for CSS background-image: url("/images/phoenix.png");. Generated path is relative instead of the path from endpoint settings. How to generate absolute path to the image from CSS(surely using image with a digest)?

Relative is absolutely what it should be. That is necessary if the system is put behind a proxy or so.

From css you should not be using an absolute path, you should be using a relative path. From CSS a url should always be relative to the current css file or should be an absolute path to another server.

Yes! This is exactly what I mean. I need to generate an absolute path to S3 from background-image property

If it is on a dedicated S3 hoster you could set a redirect on the server to redirect to what it is (either a temporary or permanent redirect as necessary), or you could statically build it in by making your CSS into a template and generating the path in-line. Or you could use brunch to preprocess the css to build in static links from some list. Or you can just put the static link in directly. Lots of options and even more than this, it depends on how dynamic you need it to be? :slight_smile:

Yes, that what I have already done - CSS into a template and generating the path in-line
But I don’t like this. I want to use CSS file with background-image property but it should point to static_url from endpoint’s settings.

You can process an eex template at compile time to generate out a css final for inclusion to brunch, all at compile time. :slight_smile:

I’d just make a whatever.css.eex file, you can even keep it in the assets area. And I’d add a mix task on compile and phx.digest that just calls into the EEx library to compile the template while passing in what I need to generate from, then just output beside it or so. :slight_smile:

Thanks. I will try this approach.