Reputation: 155
I am using variables in CSS/SCSS. I want to set a background (using an SVG file), but it is re-loading every time I navigate or perform some other action.
My -Variables.scss file:
:root {
--backgroundTheme: url('triangle-dark.svg') no-repeat;
}
$variables: (
--backgroundTheme: var(--backgroundTheme)
);
My styles.scss file:
@import "~assets/_variable";
body:before {
background-size: cover;
background: var(--backgroundTheme);
}
How can I avoid multiple times loading of this file?
PS: This is an Angular 8 project.
Upvotes: 1
Views: 890
Reputation: 91
I had the same problem recently. It was caused by the inspector - "Disable cache" was enabled:
You just need to uncheck it and it will stop making new requests.
Upvotes: 2
Reputation: 1252
I have two possible idea, not sure if they works for you but it's an easy check:
settings.scss
file and import it whenever needed in the other files. It's a personal preference, I find it easier to manage like that.Upvotes: 0
Reputation: 1
To use the image multiple times in the DOM with only one request from the CSS you should use the content
property of your pseudo element target to render the image:
body::before {
content: var(--backgroundTheme, 'alt text');
}
Although you'll probably need another approach in handling the image. It might not work for you.
Upvotes: 0