Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Background SVG asset not loading when deployed to subdirectories due to leading slash in URI #33

Closed
ranolfi opened this issue Jan 30, 2020 · 4 comments
Labels
area: frontend Changes to front-end code meta: help wanted Extra attention is needed

Comments

@ranolfi
Copy link
Member

ranolfi commented Jan 30, 2020

This one was actually brought up by @manassehkatz and we dismissed it at first, believing it to be due to GitHub Pages not rendering SVGs for security concerns, but that turned out to be incorrect.

Consider the staging deployment at https://codidact.github.io/landing-page/.

How it should look:
image

How it looks:
image

The background SVG asset https://codidact.github.io/assets/img/hero-bg.svg does not load. Notice anything?

The zen among us will notice the missing subdirectory string (landing-page/) in the resource path.

The culprit is

background-image: url("/assets/img/hero-bg.svg"), $color-gradient-alternate;
.

Since the code is "compiled" to url(/assets/img/hero-bg.svg)1, one possible solution would be:

url("../../assets/img/hero-bg.svg")

...but I'm not sure how robust that is for every case.


-

1: shame how the style guidelines aren't kept after SCSS compilation (the double quotes) :|

@mattjbrent mattjbrent added area: frontend Changes to front-end code meta: help wanted Extra attention is needed labels Jan 31, 2020
@ranolfi
Copy link
Member Author

ranolfi commented Feb 2, 2020

I wasn't aware that relative url() paths in CSS are relative to the CSS asset itself and not to the document in which it is included[1]. As such, the straightforward solution - demonstrated in terms of processed ("compiled") CSS would actually be:

url("../img/hero-bg.svg")

However, it's been a little painful getting that to work on the SCSS / Webpack setup.

It seems this is not an uncommon difficulty. See also angular/angular-cli#12797.

Couldn't sort this out!

I mean, I got it working by changing line 2 from the hero.scss file linked above to

background-image: url("../../dist/assets/img/hero-bg.svg"), $color-gradient-alternate;

and installing/setting up svg-url-loader, but this is not a proper solution as it encodes the svg to data:image/svg+xml and that's not what we would expect.

(Update: Requested guidance from DevOps leader JustinM.)

@galegosimpatico
Copy link
Contributor

galegosimpatico commented Aug 22, 2020

[...], one possible solution would be:

url("../../assets/img/hero-bg.svg")

Works for me, I think. But I edited object CSS, not source scss doc.

Not so sure about "staging" in gh-pages....

@galegosimpatico
Copy link
Contributor

galegosimpatico commented Aug 22, 2020

However it looks like solved in production. Can close now?

I think "staging" in gh-pages isn't somehow completed about this?

@Daksh14
Copy link
Member

Daksh14 commented May 31, 2021

The design is old and this is fixed, the added slash no more affects any assets

@Daksh14 Daksh14 closed this as completed May 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: frontend Changes to front-end code meta: help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants