Answers.Body: <p><strong>Limiting compatibility issues</strong></p>
  
  <ul>
  <li>Perform a validation of the file structure. See <a href="https://ebooks.stackexchange.com/q/446/136">this question</a> about this subject.</li>
  </ul>
  
  <p><strong>Making it faster to load</strong></p>
  
  <ul>
  <li>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.</li>
  <li>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.</li>
  <li>Try to keep the HTML code of you files as simple and tidy as possible. I.E. use <code>&lt;i&gt;</code> and <code>&lt;b&gt;</code> tags for italic and bold text instead of their relative <code>&lt;span style="font-style:italic"&gt;</code> and <code>&lt;span style="font-weight:bold"&gt;</code>.</li>
  <li>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.</li>
  </ul>
  
  <p><strong>Keeping it consistent</strong></p>
  
  <ul>
  <li><p>Keep the visual look as simple as possible; if you want to include some fancy layout (i.e. for chapter titles or other particular portions of text like quotes and so on) try to define it as properly and accurately as possible with CSS styles, and test the outcome with the greater number of reading devices and software that you can.</p></li>
  <li><p>If you want to use any specific font, be sure to include it in the epub file and to define its <code>@font-face</code> and styles in the CSS file.</p></li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2013-12-30T22:25:06.923Z
Answers.LastActivityDate: 2014-02-03T09:02:17.787Z
Answers.LastEditDate: 2017-04-13T13:00:05.480Z
Answers.UserDisplayName: Sekhemty
Answers.Body: <p>The <a href="http://www.idpf.org/epub/301/spec/epub-overview.html#sec-gls-fonts" rel="nofollow noreferrer">EPUB 3 specification</a><sup>1</sup> suggests including embedded fonts for compatibility:</p>
  <blockquote>
  <p>3.4 Fonts</p>
  <p>EPUB 3 does not require that Reading Systems come with any particular
  set of built-in system fonts. As occurs in Web contexts, Users in a
  particular locale might have installed fonts that omit characters
  required for other locales, and Reading Systems might utilize
  intrinsic fonts or font engines that do not utilize operating system
  installed fonts. As a result, the text content of an EPUB Publication
  might not natively render as intended on all Reading Systems.</p>
  <p>To address this problem, EPUB 3 supports the embedding of fonts to
  facilitate the rendering of text content, and this practice is
  recommended in order to ensure content is rendered as intended.</p>
  <p>Support for embedded fonts also ensures that characters and glyphs
  unique to an EPUB Publication can be embedded for proper display.</p>
  </blockquote>
  <p><sup><sup>1</sup>Epub 3 Overview - Draft Specification 8 November 2013</sup></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2013-12-31T01:17:38.523Z
Answers.LastActivityDate: 2013-12-31T01:28:14.100Z
Answers.LastEditDate: 2020-06-18T08:36:04.683Z
Answers.UserDisplayName: Jason Down
Answers.Body: <p>You cannot optimize and <em>make it faster to load and to be processed from the reader</em> in a generic way for all possible readers and probably not for all <strong>available</strong> readers¹.</p>
  
  <p>The reason is that there are conflicting elements involved that lead to different loading results on different device hardware configurations. For the reading device these configurations include:</p>
  
  <ul>
  <li>CPU speed</li>
  <li>availability of CPU cache(s) and its size</li>
  <li>work memory speed (access time, width of access path)</li>
  <li>storage memory speed if EPUB stored internal</li>
  <li>SD card interface speed and SD card read speed if the EPUB is stored externally</li>
  </ul>
  
  <p>From the above the <a href="https://en.wikipedia.org/wiki/Secure_Digital#Speeds" rel="nofollow">SD card speed</a> is most obviously variable, as SD cards are sold in different classes.</p>
  
  <p>Assuming there is no DMA involved all of the EPUB data has to go through the CPU. Uncompressing data from an EPUB (ie. ZIP </p>
  
  <p>If the storage is slow and CPU speed high, you better compress the data in an EPUB (use <a href="https://en.wikipedia.org/wiki/DEFLATE" rel="nofollow">zip DEFLATE</a>). 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&mdash;although to a lesser extend then encoding&mdash;involves trade-offs between speed and memory requirements.</p>
  
  <p>So just deciding² whether you should compress the data in an EPUB file or not&mdash;in order to <em>make them faster to load</em> is a hard to answer in general, although you should be able to do so for a <strong>specific reader</strong> after some testing.</p>
  
  <hr>
  
  <p>¹ <sub>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 <em>and</em> 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 <code>&lt;font&gt;</code> is not supported in HTML5). However an EPUB2 device might render <code>&lt;font&gt;</code> faster than something specified in a separate CSS file, especially if applied only once in the HTML file.</sub></p>
  
  <p>² <sub>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.</sub></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-01-01T19:55:02.503Z
Answers.Text: Are there really SDCards fast enough that decompressing an average ebook would take longer than ANY SDCard IO operation on even the lowest end modern CPUs?
Answers.UserDisplayName: DVK
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-01-01T20:18:13.120Z
Answers.Text: @DKV I don't know how the different parts interact and what is the limiting factor. The SDCard IO is probably slow, but even then, for low compression ratio's (as with JPEG image in an EPUB) there will be a point where you have to decide not to compress. For HTML files that is probably more clean cut in favour of compressing.
Answers.UserDisplayName: Anthon
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-01-01T10:08:21.253Z
Answers.LastActivityDate: 2014-01-01T10:08:21.253Z
Answers.UserDisplayName: Anthon
Body: <p>How can I optimize an epub file, in order, but not limited to:</p>
  
  <ul>
  <li>limit the chances of compatibility issues?</li>
  <li>make it faster to load and to be processed from the reader?</li>
  <li>keep its look consistent throughout different devices and readers?</li>
  </ul>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2013-12-30T22:26:09.647Z
Comments.Text: This question is meant to be answered with many different tips & tricks. Feel free to edit my answer to improve it or add you own if you have other ideas.
Comments.UserDisplayName: Sekhemty
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2013-12-31T10:02:31.257Z
Comments.Text: Stack Exchange works with questions that have one answer not asking for a list of tips as you have done here. Please edit the question to make it more direct
Comments.UserDisplayName: mmmmmm
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2013-12-31T10:17:54.903Z
Comments.Text: but not all questions can be answered with a single solution, what about things that can be addressed with multiple different tecniques?
Comments.UserDisplayName: Sekhemty
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2013-12-31T10:25:55.973Z
Comments.Text: Each of those techniques is a complete answer to the question. see http://ebooks.stackexchange.com/help/dont-ask
Comments.UserDisplayName: mmmmmm
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-01-01T14:58:26.983Z
Comments.Text: Also see http://meta.ebooks.stackexchange.com/questions/112/how-can-i-optimize-an-epub-file-tips-tricks-question-borders-on-off-topic-s
Comments.UserDisplayName: mmmmmm
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-01-15T21:41:12.980Z
Comments.Text: I think there are 3 good quesitons here.. and probably 20 others in the same vane.  Breaking this question up would be good.
Comments.UserDisplayName: Chad
Tags: <epub><creation><editing><optimization>
Title: How can I optimize an epub file?
UserDisplayName: Sekhemty
ThreadText: # How can I optimize an epub file?
  
  (Asked by: username_0 on 2013-12-30)
  
  How can I optimize an epub file, in order, but not limited to:
  
  * limit the chances of compatibility issues?
  * make it faster to load and to be processed from the reader?
  * keep its look consistent throughout different devices and readers?
  
  **Tags:** epub, creation, editing, optimization
  
  > **Comments:**
  > **username_0**: This question is meant to be answered with many different tips & tricks. Feel free to edit my answer to improve it or add you own if you have other ideas.  
  > **username_1**: Stack Exchange works with questions that have one answer not asking for a list of tips as you have done here. Please edit the question to make it more direct  
  > **username_0**: but not all questions can be answered with a single solution, what about things that can be addressed with multiple different tecniques?  
  > **username_1**: Each of those techniques is a complete answer to the question. see http://ebooks.stackexchange.com/help/dont-ask  
  > **username_1**: Also see http://meta.ebooks.stackexchange.com/questions/112/how-can-i-optimize-an-epub-file-tips-tricks-question-borders-on-off-topic-s  
  > **username_2**: I think there are 3 good quesitons here.. and probably 20 others in the same vane.  Breaking this question up would be good.  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_0 on 2013-12-30. Score: 5 | Accepted answer
  
  **Limiting compatibility issues**
  
  * Perform a validation of the file structure. See [this question](https://ebooks.stackexchange.com/q/446/136) about this subject.
  
  **Making it faster to load**
  
  * 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 `<i>` and `<b>` tags for italic and bold text instead of their relative `<span style="font-style:italic">` and `<span style="font-weight:bold">`.
  * 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.
  
  **Keeping it consistent**
  
  * Keep the visual look as simple as possible; if you want to include some fancy layout (i.e. for chapter titles or other particular portions of text like quotes and so on) try to define it as properly and accurately as possible with CSS styles, and test the outcome with the greater number of reading devices and software that you can.
  * If you want to use any specific font, be sure to include it in the epub file and to define its `@font-face` and styles in the CSS file.
  
  
  ---
  
  ### Answer by username_3 on 2013-12-31. Score: 4
  
  The [EPUB 3 specification](http://www.idpf.org/epub/301/spec/epub-overview.html#sec-gls-fonts)1 suggests including embedded fonts for compatibility:
  
  > 3.4 Fonts
  >
  > EPUB 3 does not require that Reading Systems come with any particular
  > set of built-in system fonts. As occurs in Web contexts, Users in a
  > particular locale might have installed fonts that omit characters
  > required for other locales, and Reading Systems might utilize
  > intrinsic fonts or font engines that do not utilize operating system
  > installed fonts. As a result, the text content of an EPUB Publication
  > might not natively render as intended on all Reading Systems.
  >
  > To address this problem, EPUB 3 supports the embedding of fonts to
  > facilitate the rendering of text content, and this practice is
  > recommended in order to ensure content is rendered as intended.
  >
  > Support for embedded fonts also ensures that characters and glyphs
  > unique to an EPUB Publication can be embedded for proper display.
  
  1Epub 3 Overview - Draft Specification 8 November 2013
  
  
  ---
  
  ### Answer by username_4 on 2014-01-01. Score: 2
  
  You cannot optimize and *make it faster to load and to be processed from the reader* in a generic way for all possible readers and probably not for all **available** readers¹.
  
  The reason is that there are conflicting elements involved that lead to different loading results on different device hardware configurations. For the reading device these configurations include:
  
  * CPU speed
  * availability of CPU cache(s) and its size
  * work memory speed (access time, width of access path)
  * storage memory speed if EPUB stored internal
  * SD card interface speed and SD card read speed if the EPUB is stored externally
  
  From the above the [SD card speed](https://en.wikipedia.org/wiki/Secure_Digital#Speeds) is most obviously variable, as SD cards are sold in different classes.
  
  Assuming there is no DMA involved all of the EPUB data has to go through the CPU. Uncompressing data from an EPUB (ie. ZIP
  
  If the storage is slow and CPU speed high, you better compress the data in an EPUB (use [zip DEFLATE](https://en.wikipedia.org/wiki/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 `<font>` is not supported in HTML5). However an EPUB2 device might render `<font>` 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.
  
  > **Comments:**
  > **username_5**: Are there really SDCards fast enough that decompressing an average ebook would take longer than ANY SDCard IO operation on even the lowest end modern CPUs?  
  > **username_4**: @DKV I don't know how the different parts interact and what is the limiting factor. The SDCard IO is probably slow, but even then, for low compression ratio's (as with JPEG image in an EPUB) there will be a point where you have to decide not to compress. For HTML files that is probably more clean cut in favour of compressing.  
  
  ---
  
  