5

求教:对于前端渲染来说,第一次打开某个 URL 和点击刷新这个 URL 有什么区别?

 1 year ago
source link: https://www.v2ex.com/t/904746
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  HTML

求教:对于前端渲染来说,第一次打开某个 URL 和点击刷新这个 URL 有什么区别?

  cogear · 50 分钟前 · 158 次点击

第一次请求某个 URL ,页面正常显示。 之后点击刷新,页面崩掉了。

出错部分逻辑

页面出错部分的逻辑是: 使用 jQuery 给parent element 添加一个 child element 。

Debug 结果

首次请求 URL 时,一切正常。 当点击浏览器刷新时,parent element 还没有渲染(还没这个 element ),就执行了上述逻辑。

所以,为何能稳定复现这个问题? 为什么首次访问这个 url 和点击刷新,js 代码逻辑的执行顺序不一样了?


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK