2018-09-02 18:38 阅读 150

连接已重置 - 加载样式表

I have written a couple functions using to both combine several stylesheets into master and secondly to set up a bunch of styles according to an admin config file. Both functions work.

The first uses

$data = file_get_contents("custom.css");
file_put_contents( "$ss","$data",FILE_APPEND);

to combine bootstrap and some other files into one.

The second uses fopen and fwrite to obtain the calculated data from mysql and dump the styles into a second stylesheet. Nothing too complicated.

The idea is to reduce http requests when it goes live and make it simpler to make changes while under development.

Occasionally when I load the website and visit different pages it fails to load either of the 2 stylesheets resulting in a messed up page. The problem occurs in both Firefox and Chrome. When it fails the browser (Firefox) returns "Problem loading page" in the tab and "The connection was reset ..." in the body.

If I reload it several times, maybe over 30 seconds, it will self-fix, but loading a different page may bring it around again.

I have tried various things including add a version to the stylesheets:

<link rel="stylesheet" href="http://www.demo-website.suffix/demo/core.css?v=1611">
<link rel="stylesheet" href="http://www.demo-website.suffix/demo/hack.css?v=1612">

Also tried without adding http://... Looking at the filesystem the files are good. The script runs almost instantaneously.

I'm wondering if I'm hitting a php issue or perhaps apache? Or anything else?

Sept 3, 2018 notes:

Error logs - I enabled php error logs, yes I found a slew of warning errors, almost all undefined variables. I then systematically fixed all the errors and rechecked the website/pages and saw no difference, no improvement.

I have wondered about the effect of reducing http requests by combining/minifying files into one or two. I've seen slow wordpress an magento websites with perhaps 15 stylesheets also javascript and a dozen plugins that do some variation of minify/combine. Perhaps the framework? When you do research into optimization and employ tools like ySlow (or replacement) or services they invariably recommend minifying and combining to improve scores. It sounds good.

Some history - when designing websites the goal for me is to make styling changes and see the changes immediately. Unfortunately some of my clients are at a loss when it comes to clearing browser cache, even with instructions.

I've seen cases where I add the no-cache lines to the head or perhaps .htaccess version and they still get old styles. Probably user error. Even with no-cache in place I commonly see a 30 second delay before the stylesheet changes take effect. There is nothing in the server config options regarding this. My thinking was that at least during the development cycle I would combine/minify the stylesheets and add timestamp versioning so that I would get immediate returns..

$version = date('YmdHis');
<link rel="stylesheet" href="<?php echo $version; ?>">

Although it typically works to load the first page, when I go to load other pages it fails and I see the error. The version updates for every page. The stylesheet.css file is good but it fails nonetheless. It gets kind of weird.

If I change the versioning to a simpler $version = 123 I don't get the 'connection reset' error but seem to be back to the 30 second hold time.

The code to prevent cacheing:

<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享