我的思维模式是不是错了?如果使用 https 调用页面,则将使用 https 调用相对 css 路径
如果您的页面使用 https 协议调用,则任何外部 css 的相对路径也将使用 https 协议调用。你真的需要加密/解密CSS内容吗? :D 但是,如果您使用绝对路径引用外部 css,则可以指定要使用的协议,通常是 http 而不是 https。也许我错了!
请让我知道我的思维模式是否完全错误。
If your page gets called using https protocol, any relative path to an external css will be called using https protocol as well. Are you really need to encrypt/decrypt css contents? :D However, if you use absolute path referring to an external css, you can specify the protocol to use, generally http rather than https. Maybe I am wrong!
Please let me know whether or not my mental model is totally wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,你是对的,相对路径将使用你当前使用的相同协议,完全限定的路径可以包含他们想要的任何协议。
您通常希望相关行为像它一样,否则如果您在
上加载
页面。http://
资源,您将收到不安全内容警告大多数浏览器中的 >https://Yes you are correct, relative paths will use the same protocol you're currently on, fully qualified paths can include whatever protocol they want.
You typically want the relative behavior to act like it does, otherwise you'll get a insecure-content warning if you're loading
http://
resources on ahttps://
page in most browsers.正如其他人回答的那样,您的模型是正确的。许多人都不知道的一个非常有趣的功能是协议相关 url。 “//www.foo.com/bar.html”是一个完全有效的 URL,并将保留当前协议。
如果您输出必须在 http 和 https 上工作但需要一些主机名(例如支持 static.foo.com / images.foo.com)的 HTML,这非常方便。
As others have answered, your model is correct. A really fun feature that many people are not aware of is protocol relative urls. "//www.foo.com/bar.html" is a perfectly valid URL and will preserve the current protocol.
This is very handy if you are outputting HTML which must work on http and https but needs some host names (e.g. to support static.foo.com / images.foo.com).
是的,相对路径指定的css/js将使用HTTPS加载。不,您不必解密内容,浏览器会为您解密。是的,你可以使用绝对路径来引用css/js,指定协议,包括HTTP。您必须小心的一件事是,某些浏览器会提示有关安全站点加载不安全内容的警告。
Yes, css/js specified by relative path will be loaded using HTTPS. No, you won't have to decrypt the contents, the browser will do it for you. Yes, you can refer to css/js by using absolute path, specifying the protocol, including HTTP. One thing you have to be careful is that some browsers will prompt a warning about a secure site loading insecure contents.