Commit 8809d422 by Qiang Xue

Fixes #5005: Added support to suppress loading the same CSS files in AJAX responses

parent ca5b8745
......@@ -60,6 +60,7 @@ Yii Framework 2 Change Log
- Enh #4643: Extra options specified in `yii\widgets\Breadcrumbs::links` will be treated as HTML attributes for the generated hyperlinks (qiangxue)
- Enh #4739: Better display of exceptions when the response format is set as "raw" format (qiangxue)
- Enh #4791: Added console output support and more colors for console commands (6pblcb, samdark, klimov-paul, Ragazzo)
- Enh #5005: Added support to suppress loading the same CSS files in AJAX responses (tof06, qiangxue)
- Enh #5223: Query builder now supports selecting sub-queries as columns (qiangxue)
- Enh #5367: Added `yii\grid\DataColumn::encodeLabel` (SDKiller)
- Enh #5480: Added defensive code to `yii\web\User::getIdentity()` to avoid potential infinite recursion (qiangxue)
......
......@@ -44,7 +44,7 @@
yii = (function ($) {
var pub = {
/**
* List of scripts that can be loaded multiple times via AJAX requests. Each script can be represented
* List of JS or CSS URLs that can be loaded multiple times via AJAX requests. Each script can be represented
* as either an absolute URL or a relative one.
*/
reloadableScripts: [],
......@@ -264,6 +264,7 @@ yii = (function ($) {
var loadedScripts = $('script[src]').map(function () {
return this.src.charAt(0) === '/' ? hostInfo + this.src : this.src;
}).toArray();
$.ajaxPrefilter('script', function (options, originalOptions, xhr) {
if (options.dataType == 'jsonp') {
return;
......@@ -280,6 +281,20 @@ yii = (function ($) {
}
}
});
$(document).ajaxComplete(function (event, xhr, settings) {
var styleSheets = [];
$('link[rel=stylesheet]').each(function () {
if ($.inArray(this.href, pub.reloadableScripts) !== -1) {
return;
}
if ($.inArray(this.href, styleSheets) == -1) {
styleSheets.push(this.href)
} else {
$(this).remove();
}
})
});
}
return pub;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment