Score:0

How to load a CSS file from a URL?

dz flag

I have a raw github page with CSS:

https://raw.githubusercontent.com/USER/REPOSITORY/main/website/style.css

How to load it in my website to effect the website globally?

I tried this in /core/themes/olivero/olivero.libraries.yml but no change occured after cache rebuild.

global-styling:
  version: VERSION
  css:
    base:
      css/base/fonts.css: {}
      css/base/base.css: {}
      css/base/utility.css: {}
      css/base/https://raw.githubusercontent.com/USER/REPOSITORY/main/website/style.css: {}
themer avatar
dz flag
@Hudri I am not sure because I don't want to do it for a module, rather globally, for all the website. I have also tried something on `olivero.libraries.yml` that didn't work. I'll edit to expand.
themer avatar
dz flag
I have edited because I believe my question is unrelated to module development, rather, to core customization.
ru flag
Simple rule: Never edit core. Create a custom theme or a custom module, both will do for this usecase.
themer avatar
dz flag
I am well aware of that rule :) I never edit core unless it's one line about CSS or one line about JS. This is indeed my need here.
ru flag
You either loose the ability to upgrade or your changes break at the next update. does not matter if it is 1 line or 1000.
themer avatar
dz flag
@Hudri correct but if, with each upgrade, I inject the same new line somehow, yes, it's "corky" but works.
berliner avatar
bd flag
@themer Most of all, it's not necessary to change core files. There are simple and well documented ways to achieve what you want.
Score:1
us flag

External files can be used, but for a CSS file the definition is similar to the following one.

https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css: { type: external, minified: true }

type: external is necessary to make Drupal know that is an external file; minified: true is used only when the file is minified.

As comments already said, it is a bad idea to change a Drupal core file because those changes are lost all the times Drupal is updated. Instead, it is better to create a custom theme, which can also use the core theme as parent theme.

themer avatar
dz flag
I can't get the file to load. I have updated about how I use the link.
apaderno avatar
us flag
Questions cannot be edited, if they invalidate the given answers. They are not for a back-and-forth with the users who answer them.
themer avatar
dz flag
Okay then I guess I should ask a new question.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.