HTML CSS Inclusion
Might be a silly question, just wanted to know do the following ways on including CSS have any impact on the server response time. If yes, which is the better method an开发者_运维技巧d how
Way 1 :
<link rel='stylesheet' href='css/some.css'/>
Way 2 :
<link rel='stylesheet' href='http://www.somesite.com/css/some.css'/>
No, your browser converts any URL into an absolute URL before making the request, so it won't make any difference.
Depends. If you want to have the same website to run in the dev, test as well as prod environments without changing code, you'd like to use relative paths. Instead of that you can also specify a <base>
element so that you only need to specify the domain only once -if necessary dynamically using a server-side language.
Another thing to take into account when hardcoding the protocol (the http:
part) is that you would like to use at least protocol-relative URL's when your website may switch between HTTP and HTTPS regulary. A CSS file which is hardcoded on http://example.com/style.css
may cause security complaints in most webbrowsers about "unsafe content". In such case you'd like to use relative paths such as style.css
or if you persist in using the full domain name, use //example.com/style.css
instead. This by the way also applies on all other resources like Javascripts and (CSS) images.
精彩评论