Mobile app version of vmapp.org
Login or Join
Jessie594

: Which is better for linking to external resources on a webpage? What is the recommended way for linking to external CSS files and JavaScript files on a HTTPS secure webpage, e.g is it better

@Jessie594

Posted in: #Cdn #Cloudflare #Https

What is the recommended way for linking to external CSS files and JavaScript files on a HTTPS secure webpage, e.g is it better to use:

//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css


or
cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css

10.04% popularity Vote Up Vote Down


Login to follow query

More posts by @Jessie594

4 Comments

Sorted by latest first Latest Oldest Best

 

@Gonzalez347

Use Github its best for this. You can store css and javascript files and there is no http or https issue.

10% popularity Vote Up Vote Down


 

@Rambettina238

If the page is on HTTPS, and will only ever be accessed over HTTPS then it doesn't make any difference. (Well, the scheme-relative URL is 6 fewer bytes before compression).

If the page will sometimes be accessed over HTTP and sometimes over HTTPS then using a scheme relative URL will make it work consistently.

If the page will sometimes be accessed over HTTPS and sometimes as a local file, then a scheme relative URL will break (because file://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css doesn't exist).

There isn't a "best", just different priorities.

10% popularity Vote Up Vote Down


 

@Berumen354

Most browsers block script from unsafe sources.
We have seen this issue while changed http to https so, we had to change source of scripts from http to https sources

for example:
code.jquery.com/jquery-2.1.4.min.js

changed to
code.jquery.com/jquery-2.1.4.min.js


similar modification done for all website content sources(script,css,images)

for https site, all content should be loaded from https sources.

10% popularity Vote Up Vote Down


 

@LarsenBagley505

For compatibility sake, I'd recommend the full absolute URL (second URL) in your case. I'm not sure how many browsers support protocol-less URLs but I bet some older browsers like netscape won't understand protocol-less URLs.

If you're trying to save the number of bytes on a page used for linking to external resources, then have your resources stem from the same folder, then add the following between the <head> and </head> of your HTML:

<base href="http://example.com/path/to/all/assets/">


The value for href is the base folder where all your resources are stored plus a trailing slash.

Then if all assets are in the exact same folder, you can easily call them by filename such as:

<img src="somefile.jpg" width=100 height=200 alt="a picture">

<script src="somescript.js">
</script>


If all the above HTML is used unmodified in the same webpage, then the image requested will be:
example.com/path/to/all/assets/somefile.jpg

and the javascript file to load will be:
example.com/path/to/all/assets/somefile.js

This is because the base tag sets the default folder for the resources on the page.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme