Comments (6)
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.
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.
Awesome, do you fancy making a PR for this?
from csz.
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.
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.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from csz.