我正在尝试在 window.history.pushState('','',url);
function goto(event,el)
{
url=el.href;
event.preventDefault();
window.history.pushState('','',url);
//$('html').load(url);
$.get(url, function(data) {
var head=data.match(/<head[^>]*>[\s\S]*<\/head>/gi);
$('head').html(head[0]);
//$('#content').html($(data).find('#content').html());
var body=data.match(/<body[^>]*>[\s\S]*<\/body>/gi)
$('body').html(body[0]);
});
}
HTML 在 CSS 之前加载,将有大约 1-2 秒的裸 html 显示,然后 css 完全加载
我所有的页面都不一样,所以我每次都必须加载不同的 css、脚本。
有没有什么方法可以比 html 更快地加载 css,或者有没有更好的方法来加载整个页面或用新页面替换当前页面内容。
我真的不想用任何插件
最佳答案
简单的解决方案是尝试在页面加载时使用 Spinner 或加载器,这可以防止您使用裸 HTML 表单用户 这是链接 How to show Page Loading div until the page has finished loading
关于javascript - 在不刷新的情况下加载新页面时 CSS 加载缓慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57253138/