[WordPress] 外掛分享: Appcachify

首頁外掛目錄 › Appcachify
WordPress 外掛 Appcachify 的封面圖片
10+
安裝啟用
★★★★★
5/5 分(2 則評價)
4256 天前
最後更新
問題解決
WordPress 3.8+ v0.1 上架:2014-07-23

內容簡介

該外掛會在您的網站頁尾添加一個指向 example.com/manifest 的 iframe。

那個 URL 是一個引用生成的 manifest 檔案 example.com/manifest.appcache的空白頁面。

manifest 本身是以下列方式建立:

增加所有排隊腳本和樣式的 URL
搜尋主題檔案和資料夾以尋找任何圖像或其他靜態資產
如果主題有 307.php 樣板,則會用作離線備援
添加最近修改的文件時間戳記,以強制 appcache 刷新

所有這些的結果是您的主要靜態檔案在訪客的設備上被本地存儲。對於移動設備,這極大地有助於改善下載和呈現時間。

文件
將項目添加到 Manifest

Appcache 可以存儲更多的東西,您可以緩存整個頁面或為離線使用者增加備援。

Manifest 有三個主要部分:

CACHE

主要的 CACHE 部分是用於明確緩存的 URL。

<?php
add_filter( 'appcache_cache', function( $urls ) {
$urls[] = '/page-available-offline/';
return $urls;
} );
?>

NETWORK

此部分用於指定不應緩存的 URL。

<?php
add_filter( 'appcache_network', function( $urls ) {
$urls[] = '*';
$urls[] = '/online-only-page/';
return $urls;
} );
?>

FALLBACK

回傳中允許您設置回傳頁面或圖像,如果使用者離線。

<?php
add_filter( 'appcache_fallback', function( $patterns ) {
$patterns[] = 'wp-content/uploads/ wp-content/uploads/offline.jpg';
return $patterns;
} );
?>

更新標題

當 manifest 檔案內容更改時,會重新獲取 appcaches,因此,我們在文件頂部添加幾個項目作為註釋。

目前的主題(如果有版本)
我們在服務器路徑中找到的任何檔案的最近修改時間

我們找到的所有檔案的大小

get_var(“SELECT post_modified FROM $wpdb->posts WHERE post_type = ‘post’ ORDER BY post_modified DESC LIMIT 1”);
return $headers;
} );
?>

關於 Appcache 的更多資訊

我強烈建議閱讀以下文章,以了解您可以使用 Appcache 做什麼:

HTML5 Rock ’s Introduction to Appcache
Application cache is a douchebag

外掛標籤

開發者團隊

⬇ 下載最新版 (v0.1) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「Appcachify」→ 直接安裝(推薦)

原文外掛簡介

The plugin adds an iframe to the footer of your website which points to example.com/manifest.
That URL is an empty page that references the generated manifest file at example.com/manifest.appcache.
The manifest itself is built in the following way:

adds URLs of all queued scripts and styles
searches theme files and folder for any images or other static assets
if a theme has a 307.php template it is used as an offline fallback
a timestamp of the most recently modified file is added to force appcache to refresh

The net result of all this is that your main static files are stored locally on your visitors devices. For mobile this greatly helps to improve download and rendering times.
Documentation
Adding items to the manifest
Appcache can do more than store static assets. You could cache entire pages, or add fallbacks for when a user is offline.
There are 3 main sections to a manifest:
CACHE
The main CACHE section is for URLs that should be explicitly cached.

NETWORK
This section is for specifying URLs that should never be cached.

FALLBACK
The fallback section allows you to set fallback pages or images if the user is offline.

The update header
Appcaches are refetched when the manifest file content changes so we add a few items as comments at the top of the file.

The current theme (and version if available)
The most recent modified time of any files we find the server path for

The size of all the files that we find a server path for
get_var( “SELECT post_modified FROM $wpdb->posts WHERE post_type = ‘post’ ORDER BY post_modified DESC LIMIT 1” );
return $headers;
} );
?>

More about appcache
I strongly recommend learning more about what you can do with appcache by reading the following articles:

HTML5 Rock’s Introduction to Appcache
Application cache is a douchebag

延伸相關外掛

文章
Filter
Apply Filters
Mastodon