サイトリニューアルしたけど、一部のページが表示されたあともずっと読み込み中のままぐるぐる矢印が回ってた問題、何が重いのか分からなかったが、やっと判明。
受賞作候補作のアマゾンリンクつけてるページが重かったわけだが、amazonアソシエイトの画像リンクについてくる1px画像が原因だった。
ためしにいくつかのページで1px画像を削除したら、すぐ表示完了した。
しかしアマゾンリンクは年度ごとに少ないときでも5個、多いとき(コミック巻数多いなど)は数十個ある。1つ1つ修正するのはうんざりなので、CMSの強みで一括でできないか考えた。
以下のMODXのスニペットを作った。
アソシエイトの画像リンクは
<a href="http://www.amazon.co.jp/gp/product/**ほげほげ**&tag=アソシエイトID"><img border="0" src="画像のURL&tag=アソシエイトID" ></a><img src="http://ir-jp.amazon-adsystem.com/**ほげ**" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />
という形なので、ページに書き出すときにaタグで囲まれている部分のみ取り出せばいい。
スニペット名は a取り出す
phpの正規表現でこう書く。
$output = preg_match("/<a(.*?)<¥/a>/", $output, $match);
print $match[0];
preg_matchの使い方はこちらを参考
画像ダグを記載してるテンプレート変数に
[+TV変数:a取り出す+]
として無事1px画像をページに書き出さないようにできました。
この1px画像、デザイン上も邪魔なのでcssで非表示にしてたんですが、元から書き出さないほうがスマート。
ポイント[[filesize? &file=`filename` &unit=`unit` ]]
Where:
filename - the path to file (for example: assets/file/index.htm)
unit - the maximum unit (for example: KB)
<script type="text/javascript" src="manager/media/script/mootools/mootools.js"></script>
<script type="text/javascript" src="assets/templates/modxhost/drop_down_menu.js"></script>
<link rel="stylesheet" href="/assets/snippets/maxigallery/slimbox/css/slimbox.css" type="text/css" media="screen" />
<script type="text/javascript" src="/assets/snippets/maxigallery/slimbox/js/mootools.js"></script>
<script type="text/javascript" src="/assets/snippets/maxigallery/slimbox/js/slimbox_lang_en.js"></script>
<script type="text/javascript" src="/assets/snippets/maxigallery/slimbox/js/slimbox.js"></script>
<link rel="stylesheet" href="/assets/snippets/maxigallery/css/default.css" type="text/css" media="screen" />
<script type="text/javascript" src="manager/media/script/mootools/mootools.js"></script>となって、mootools.jsは一回のみになり、無事slimboxが動くようになりました。
<script type="text/javascript" src="assets/templates/modxhost/drop_down_menu.js"></script>
<link rel="stylesheet" href="/assets/snippets/maxigallery/slimbox/css/slimbox.css" type="text/css" media="screen" />
<script type="text/javascript" src="/assets/snippets/maxigallery/slimbox/js/slimbox_lang_en.js"></script>
<script type="text/javascript" src="/assets/snippets/maxigallery/slimbox/js/slimbox.js"></script>
<link rel="stylesheet" href="/assets/snippets/maxigallery/css/default.css" type="text/css" media="screen" />
<script type="text/javascript" src="assets/js/jquery.js"></script>
<script type="text/javascript" src="assets/js/fixHeight.js"></script>
<script type="text/javascript">
<!--
jQuery.noConflict();
var j$ = jQuery;
-->
</script>
<script type="text/javascript" src="manager/media/script/mootools/mootools.js"></script>
<script type="text/javascript" src="assets/templates/modxhost/drop_down_menu.js"></script>
<?php
echo 'Copyright © '.date('Y').'';
?>
date() [function.date]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Tokyo' for 'JST/9.0/no DST' instead
<?php
ini_set("date.timezone", "Asia/Tokyo");
echo 'Copyright © '.date('Y').'';
?>
date.timezone = Asia/Tokyo
[[Ditto? &parents=`1` &sortBy=`pub_date` &display=`all` &tpl=`testTpl` &dateSource=`pub_date` &dateFormat=`%Y.%m.%d` &showPublishedOnly=`1`]]
<h2><a href="[~[+id+]~]">[+title+]</a></h2>
<p>[+introtext+]</p>
<p>
[[Ditto? &parents=`5` &sortBy=`menuindex` &sortDir=`ASC` &display=`all` &tpl=`testTpl2` &showPublishedOnly=`1` ]]</p>
<a href="[~id~]">
<a href="#アンカー名">
<a href="[~[*id*]~]#アンカー名">
]]>
[[Ditto? &parents=`親ドキュメントID` &display=`all` &tpl=`LinkTpl` &dateSource=`pub_date` &dateFormat=`%Y.%m.%d` &showPublishedOnly=`1`]]
<h4><a href="[~[+id+]~]" title="[+pageTitle+]" target="_blank">[+pagetitle+]</a></h4>
<p>[+description+]</p>
<h3>カテゴリー1</h3>
[[Ditto? &parents=`親ドキュメントID` &display=`all` &tpl=`LinkTpl` &dateSource=`pub_date` &dateFormat=`%Y.%m.%d` &showPublishedOnly=`1` &tagDelimiter=`,` &tagMode=`onlyTags` &tags=`カテゴリー1` &tagData=`longtaitle`]]
<h3>カテゴリー2</h3>
[[Ditto? &parents=`親ドキュメントID` &display=`all` &tpl=`LinkTpl` &dateSource=`pub_date` &dateFormat=`%Y.%m.%d` &showPublishedOnly=`1` &tagDelimiter=`,` &tagMode=`onlyTags` &tags=`カテゴリー2` &tagData=`longtaitle`]]
<html>
とか入らない。