一千萬個為什麽

搜索

我如何優化epub文件?



我如何優化一個epub文件,以便但不限於:

  • 限制兼容性問題的幾率?
  • 使其更快加載並從閱讀器處理
  • 在不同的設備和閱讀器中保持其外觀一致?

轉載註明原文: 我如何優化epub文件?

一共有 3 個回答:

限制兼容性問題

  • 執行文件結構的驗證。有關此主題,請參閱此問題

加載速度更快

  • Keep the size of individual internal HTML files small. The reader usually load them individually when needed, and it is (obviously) faster to load a small file than a big one; as a rule of thumb the size limit is considered to be 250~300 KB. It is better to have many smaller files than a single heavy one, so try to have any file cover a single chapter or section rather than the whole book.
  • Always to keep the individual files smaller and to reduce required processing power, use a distinct stylesheet to define the CSS styles, rather than putting them inside each individual HTML text file.
  • Try to keep the HTML code of you files as simple and tidy as possible. I.E. use and tags for italic and bold text instead of their relative and .
  • If you are including images, keep their size as small as possible. Consider the screen resolutions of the devices where the book will be read, whether they have color or B/W displays, and if the images are photographies or other complex illustrations, or instead simple drawings or diagrams.

保持一致

  • 保持視覺效果盡可能簡單;如果你想包含一些花哨的布局(例如章節標題或文本的其他特定部分,如引號等),盡可能使用CSS樣式盡可能準確,準確地定義它,並使用更多的閱讀設備來測試結果和你可以的軟件。

  • 如果您想使用任何特定字體,請確保將其包含在epub文件中,並在CSS文件中定義其 和樣式。

EPUB 3規範 1 建議包含嵌入字體的兼容性:

3.4字體     EPUB 3並不要求閱讀系統具有任何特殊性   一套內置的系統字體。正如Web上下文中發生的那樣,a中的用戶   特定的語言環境可能安裝了忽略字符的字體   其他地區需要,閱讀系統可能會使用   內部字體或不使用操作系統的字體引擎   安裝字體。因此,EPUB出版物的文本內容   可能無法在所有閱讀系統上按照預期進行本地呈現。     為了解決這個問題,EPUB 3支持嵌入字體   方便文本內容的呈現,而這種做法是   推薦使用,以確保內容按預期呈現。     支持嵌入字體還可以確保字符和字形   可以嵌入EPUB出版物獨有的顯示功能。

1 Epub 3概述 - 2013年11月8日規範草案

對於所有可能的讀者,您可能無法優化和加快讀取器加載和處理的速度,也可能不適用於所有可用閱讀器¹。

原因在於存在相互矛盾的元素,導致不同設備硬件配置上的不同加載結果。對於閱讀設備,這些配置包括:

  • CPU速度
  • CPU緩存的可用性及其大小
  • 工作內存速度(訪問時間,訪問路徑的寬度)
  • 如果EPUB存儲在內部,則存儲內存速度
  • 如果EPUB存儲在外部,則SD卡接口速度和SD卡讀取速度

從上面可以看出, SD卡速度顯然是可變的,因為SD卡的銷售方式不同類。

假設不涉及DMA,則所有的EPUB數據必須通過CPU。從EPUB解壓縮數據(即ZIP

If the storage is slow and CPU speed high, you better compress the data in an EPUB (use zip DEFLATE). If storage is fast and CPU speed low than you better not compress the data in an EPUB (use zip STORE). Decompressing compressed data from an EPUB file is non-trivial, including bit manipulations and tables. Implementing a decoding library for DEFLATE—although to a lesser extend then encoding—involves trade-offs between speed and memory requirements.

So just deciding² whether you should compress the data in an EPUB file or not—in order to make them faster to load is a hard to answer in general, although you should be able to do so for a specific reader after some testing.


¹ In this example I only approach the compression vs non-compression issue to make a point. Other elements that at first glance don't seem to have a global optimal solution: 1) Size of images so they don't require rescaling on any device and have maximum detail. 2) Use the deflate algorithm on JPEG images to get a little bit of extra compression for a double decompression to pixel information. 3) EPUB2 vs. EPUB3 issues. E.g. EPUB3 forces use of CSS for things like font size (as is not supported in HTML5). However an EPUB2 device might render faster than something specified in a separate CSS file, especially if applied only once in the HTML file.

² The resulting difference of any particular trade-off might be minuscule compared to other things that influence loading speed. That is of course irrelevant: every tiny bit helps, some just more than others.