Javascript – How to force or add the content length for ajax type POST requests in Firefox – iTecNote

您所在的位置:网站首页 火狐post Javascript – How to force or add the content length for ajax type POST requests in Firefox – iTecNote

Javascript – How to force or add the content length for ajax type POST requests in Firefox – iTecNote

#Javascript – How to force or add the content length for ajax type POST requests in Firefox – iTecNote| 来源: 网络整理| 查看: 265

Related SolutionsJavascript – How to force the browser to reload cached CSS and JavaScript files

This solution is written in PHP, but it should be easily adapted to other languages.

The original .htaccess regex can cause problems with files like json-1.3.js. The solution is to only rewrite if there are exactly 10 digits at the end. (Because 10 digits covers all timestamps from 9/9/2001 to 11/20/2286.)

First, we use the following rewrite rule in .htaccess:

RewriteEngine on RewriteRule ^(.*)\.[\d]{10}\.(css|js)$ $1.$2 [L]

Now, we write the following PHP function:

/** * Given a file, i.e. /css/base.css, replaces it with a string containing the * file's mtime, i.e. /css/base.1221534296.css. * * @param $file The file to be loaded. Must be an absolute path (i.e. * starting with slash). */ function auto_version($file) { if(strpos($file, '/') !== 0 || !file_exists($_SERVER['DOCUMENT_ROOT'] . $file)) return $file; $mtime = filemtime($_SERVER['DOCUMENT_ROOT'] . $file); return preg_replace('{\\.([^./]+)$}', ".$mtime.\$1", $file); }

Now, wherever you include your CSS, change it from this:

To this:



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3