-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Google fonts are loaded as <script> instead of <link> #174
Comments
Ooh good one, logic for this resides here: https://github.com/CompuIves/codesandbox-client/blob/master/src/sandbox/external-resources.js. Maybe we should either do a manual check, or do a preflight request to find out the |
It would be nice if the API could figure out the resource type when you add it (even return an error if it's neither JS, nor CSS), and return it. I don't know about the backwards compatibility, though. |
I'm interested in working on this. It seems like you could just use a function addResource(resource: string) {
const match = resource.match(/\.([^.]*)$/);
if (match && match[1] === 'css') {
addCSS(resource);
} else if (match && match[1] === 'js') {
addJS(resource);
} else {
head(resource).then((response) => {
// Check reponse
if (contentType(response) === 'text/css') {
addCSS(resource)
} else {
addJS(resource);
}
}).catch((e) => {
// Should we log an error?
addJS(resource)
})
}
} Some questions:
|
That's really great @tansongyang! Your proposal sounds great. Answering the questions:
I think we should log the error using |
@CompuIves OK. One possible issue with |
@tansongyang No problem! We polyfill fetch, so it should also work on IE11. |
Maybe also check for javascript |
Sounds good, throwing an error is the best way. This way we can notify the
developer that an external resource isn't available.
…On Tue, Sep 12, 2017, 10:05 lbogdan ***@***.***> wrote:
Maybe also check for javascript Content-Type and error otherwise?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#174 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAj1CHgtDUrTbuQ0i-FR6LWs71uu4fdRks5shjsxgaJpZM4PLV8W>
.
|
Sounds good. I'll post here when I have a PR. |
Made PR. See the comments and commit messages for more details. |
As a workaround, it looks like you can just add '.css' to the end of the url and it'll work: https://fonts.googleapis.com/css?family=Roboto:400,700.css |
Same thing happens with Material icons: https://fonts.googleapis.com/icon?family=Material+Icons. And adding |
If you add the weight, it works: |
Closing this as we can now load scripts and style-sheets from |
The text was updated successfully, but these errors were encountered: