Kaynağa Gözat

Prefectch : précharge les icônes

Précharge les icônes qui ne sont pas forcément affichées sur la page en
cours (par exemple l'icône favoris) pour éviter d'avoir un bref instant
sans icône lors du changement d'état (par exemple lorsqu'on marque un
article comme favoris)
Alexandre Alapetite 12 yıl önce
ebeveyn
işleme
4f0b1efc2b
2 değiştirilmiş dosya ile 7 ekleme ve 2 silme
  1. 4 0
      app/layout/layout.phtml
  2. 3 2
      app/models/RSSThemes.php

+ 4 - 0
app/layout/layout.phtml

@@ -20,6 +20,10 @@
 <?php if (isset ($this->rss_url)) { ?>
 		<link rel="alternate" type="application/rss+xml" title="<?php echo $this->rss_title; ?>" href="<?php echo Url::display ($this->rss_url); ?>" />
 <?php } ?>
+		<link rel="prefetch" href="<?php echo RSSThemes::icon('starred', true); ?>">
+		<link rel="prefetch" href="<?php echo RSSThemes::icon('non-starred', true); ?>">
+		<link rel="prefetch" href="<?php echo RSSThemes::icon('read', true); ?>">
+		<link rel="prefetch" href="<?php echo RSSThemes::icon('unread', true); ?>">
 		<meta name="robots" content="noindex,nofollow" />
 	</head>
 	<body>

+ 3 - 2
app/models/RSSThemes.php

@@ -47,7 +47,7 @@ class RSSThemes extends Model {
 		), 1) : array();
 	}
 
-	public static function icon($name) {
+	public static function icon($name, $urlOnly = false) {
 		static $alts = array(
 			'add' => '✚',
 			'all' => '☰',
@@ -82,6 +82,7 @@ class RSSThemes extends Model {
 		$url = isset(self::$themeIcons[$url]) ? (self::$themeIconsUrl . $url) :
 			(self::$defaultIconsUrl . $url);
 
-		return '<img class="icon" src="' . Url::display($url) . '" alt="' . $alts[$name] . '" />';
+		return $urlOnly ? Url::display($url) :
+			'<img class="icon" src="' . Url::display($url) . '" alt="' . $alts[$name] . '" />';
 	}
 }