Asked • 04/23/19

Is it valid to replace http:// with // in a <script src="http://...">?

I have the following element: <script type="text/javascript" src="https://cdn.example.com/js_file.js"></script>In this case the site is HTTPS, but the site may also be just HTTP. (The JS file is on another domain.) I'm wondering if it's valid to do the following for convenience sake: <script type="text/javascript" src="//cdn.example.com/js_file.js"></script>I'm wondering if it's valid to remove the `http:` or `https:`?It seems to work everywhere I have tested, but are there any cases where it doesn't work?

1 Expert Answer

By:

Gabriel F. answered • 11/05/19

Tutor
5.0 (85)

Full Stack Software Developer and Mentor

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.