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

[html] 第91天 请描述下元素的href和src有什么区别? #757

Open
haizhilin2013 opened this issue Jul 15, 2019 · 5 comments
Open
Labels
html html

Comments

@haizhilin2013
Copy link
Collaborator

第91天 请描述下元素的href和src有什么区别?

@haizhilin2013 haizhilin2013 added the html html label Jul 15, 2019
@shejiJiang
Copy link

shejiJiang commented Jul 15, 2019

1.概念不同
href用于在当前文档和引用资源之间确立联系
src用于将资源替换当前元素
2.解析方式不同
href解析时,会并行下载资源且不会停止当前文档处理
src解析时,会暂停当前文档处理

@xjt31012
Copy link

href 的属性值是链接,是链接的目标
src 属性值是文件的路径或地址,是引用资源

@nowherebutup
Copy link

1.href:获取位置,建立连接; src:请求资源,并下载获取
2.href;异步解析文件; src:同步解析,会中断当前文件的解析

@pokerLife
Copy link

记得做过

@Konata9
Copy link

Konata9 commented Aug 22, 2019

href 只是建立一个与目标地址的关系。比如 link,a。浏览器读到 href 的时候不会暂停解析(link 中由于是 CSS 相关,在生成 Render Tree 的时候可能需要等待)。

src 相当于把指定的资源潜入到标签中。因此需要有下载、编译、执行这个过程。在这个过程走完前,浏览器的页面加载和渲染会被暂停。因此才会有把 script 标签放到 body 最后、img 标签的 src 等页面加载后在替换成真正的 src(懒加载)等操作。

参考文档:
url、href、src 详解

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

No branches or pull requests

6 participants