Skip to content
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

Sometimes, like with Google Fonts, there's no extension at the end of the URL #39

Open
michelollivier opened this issue Mar 14, 2017 · 4 comments

Comments

@michelollivier
Copy link

Hi,
Sometimes, like with Google Fonts, there's no extension at the end of the URL. Then we'll need to set the resource type to help toast to load the resource as expected :

load('[css]https://fonts.googleapis.com/css?family=Open+Sans');

it requires to modify code with something like
` if (/.css$/.test(path)) {

isCss = true;

// css
e = doc.createElement('link');
e.rel = 'stylesheet';
e.href = path;

} else if (/^[css].+/.test(path)) {

isCss = true;

// css
e = doc.createElement('link');
e.rel = 'stylesheet';
e.href = path.substring(5);   

} else if (/^[js].+/.test(path)) {

// javascript
e = doc.createElement('script');
e.src = path.substring(4);;
e.async = async === undefined ? true : async;

} else {

// javascript
e = doc.createElement('script');
e.src = path;
e.async = async === undefined ? true : async;

}`

Regards
Michel

@amorey
Copy link
Member

amorey commented Mar 14, 2017

Thanks for the suggestion! This issue actually came up recently (#23) and at the time we decided to recommend that users add #.css as a workaround until we come up with a more permanent solution (i.e. loadjs('https://fonts.googleapis.com/css?family=Open+Sans#.css')).

If we want to handle this in a more permanent way, I'm partial to using "css+" as a prefix over "[css]" but I'm curious to hear what others think. Is there a standard syntax for indicating the expected content-type of a file in a url?

@michelollivier
Copy link
Author

Not really. As I know require.js uses "css!".

@amorey
Copy link
Member

amorey commented Mar 15, 2017

Ok, thanks. Can you use #.css for now until we get more feedback?

Do you have a preference between "[css]", "css+", "css!" syntax?

@amorey
Copy link
Member

amorey commented Mar 28, 2017

@michelollivier I added support for "css!" prefix to the latest version of LoadJS (3.5.0):
https://github.com/muicss/loadjs
https://www.npmjs.com/package/loadjs

Let me know if you run into any problems using the feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants