Coder Social home page Coder Social logo

当浏览器开启缓存的时候,第一次打开页面可以正常显示twikoo,但F5刷新就直接消失,需要从别的页面跳过来才能显示 about twikoo HOT 6 CLOSED

tinsir avatar tinsir commented on June 6, 2024 1
当浏览器开启缓存的时候,第一次打开页面可以正常显示twikoo,但F5刷新就直接消失,需要从别的页面跳过来才能显示

from twikoo.

Comments (6)

tinsir avatar tinsir commented on June 6, 2024

控制台的错误请忽略

from twikoo.

imaegoo avatar imaegoo commented on June 6, 2024

js顺序的问题,twikoo要放在chunk之前加载

image

image

from twikoo.

tinsir avatar tinsir commented on June 6, 2024

@imaegoo 感谢回复 研究了一下 或许和js顺序有关。我用了其它方式解决,并且我有一些不太理解
关于 CDN 镜像
https://lib.baomitu.com/twikoo/1.6.29/twikoo.all.min.js 404 为啥404?
https://cdn.staticfile.org/twikoo/1.6.29/twikoo.all.min.js Cache-Control: max-age=2 为啥只给2秒?

我开始出问题是用的https://cdn.staticfile.org/twikoo/1.6.29/twikoo.all.min.js
原因也出在Cache-Control: max-age=2

切换到https://cdn.bootcdn.net/ajax/libs/twikoo/1.6.29/twikoo.all.min.js Cache-Control: max-age=31536000
就完全正常了 之前是两秒过期 现在缓存时间长了到没问题了
希望作者能把baomitu这个恢复一下 现在404用不了 这个国内外速度都挺快

from twikoo.

imaegoo avatar imaegoo commented on June 6, 2024

我用了其它方式解决,并且我有一些不太理解

和 js 的加载顺序有关,和缓存无关,Cache-Control 不能解决根本问题,建议调整 js 的加载顺序,确保“声明”在“调用”之前执行。

<!-- 声明 -->
<div id="tcomment"></div>
<script src="https://cdn.staticfile.org/twikoo/1.6.29/twikoo.all.min.js"></script>
<!-- 调用 -->
<script>
twikoo.init({ ... })
</script>

声明必须在调用之前,之所以缓存之后没有出现问题,是因为<script defer ...>无法保证js的执行先后顺序,被缓存的twikoo js文件恰巧先于网站js执行了,造成了“缓存以后就正常了”的现象。

为啥404?

其中一些 CDN 可能需要数天时间同步最新版本

希望作者能把baomitu这个恢复一下 现在404用不了 这个国内外速度都挺快

CDN 并不是 twikoo 作者维护的,baomitu 由 360 维护,CDN 厂商会定时同步最新版本的 js

from twikoo.

tinsir avatar tinsir commented on June 6, 2024

好的。🙏thanks

from twikoo.

famousprince avatar famousprince commented on June 6, 2024

cdn.staticfile.org / cdn.staticfile.net / lib.baomitu.com 替换成 -> s4.zstatic.net/ajax/libs,有 CDN 加载快,同步也很及时

from twikoo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.