Giter VIP home page Giter VIP logo

Comments (6)

lukejacksonn avatar lukejacksonn commented on June 6, 2024

This sounds doable.. I haven't used <base href=/PATH/ > in a while. Is there a way to pick this up in Javascript an if so is it just a case of prefixing the urls with this variable?

from csz.

MeloJR avatar MeloJR commented on June 6, 2024

You can use document.baseURI for get the url with protocol and domain or new URL(document.baseURI).pathname in order to get the path only. You should take care if the baseURI finished in / to avoid having // in the URL.

from csz.

lukejacksonn avatar lukejacksonn commented on June 6, 2024

Awesome, do you fancy making a PR for this?

from csz.

MeloJR avatar MeloJR commented on June 6, 2024

I was thinking about it and I think that it is better to add support for relative paths (path that starts with ./) so fetch uses document.baseURI automatically.

Basically from this

const isExternalStyleSheet = key => /^(\/|https?:\/\/)/.test(key.trim());

to

const isExternalStyleSheet = key => /^(\/|\.\/|https?:\/\/)/.test(key.trim());

What do you think? I think it is a better solution.

from csz.

lukejacksonn avatar lukejacksonn commented on June 6, 2024

This certainly sounds like a better option! A much less involved change.. have you tested it and does it work for your use case and not break others?

(sincere apologies for no tests)

from csz.

MeloJR avatar MeloJR commented on June 6, 2024

I test it in my project and it works well but I don't test it in other cases. I think it should not break anything unless you use a class name that starts with / something like ./WHATEVER (I think that it is not normal but a valid css class name). Maybe the regex has to test about the file extensión to avoid conflicts with some rare class names. The problem with this last approach is that if you serve files behind a server without a file extension in the url (like https://MY_URL/styles/App) it will failed. The problem with the rare class names can be avoid by the user changing

css`
  ./NAME { ...properties }
`

to

css`
  & {
    ./NAME { ...properties }
  }
`

What do you think?

from csz.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.