diff --git a/src/calibre/srv/render_book.py b/src/calibre/srv/render_book.py index 913fa590e6..ac0b815daa 100644 --- a/src/calibre/srv/render_book.py +++ b/src/calibre/srv/render_book.py @@ -215,6 +215,7 @@ class Container(ContainerBase): resource_template = link_uid + '|{}|' xlink_xpath = XPath('//*[@xl:href]') link_xpath = XPath('//h:a[@href]') + res_link_xpath = XPath('//h:link[@href]') def link_replacer(base, url): if url.startswith('#'): @@ -249,6 +250,14 @@ class Container(ContainerBase): elif mt in OEB_DOCS: self.virtualized_names.add(name) root = self.parsed(name) + for link in res_link_xpath(root): + ltype = (link.get('type') or 'text/css').lower() + rel = (link.get('rel') or 'stylesheet').lower() + if ltype != 'text/css' or rel != 'stylesheet': + # This link will not be loaded by the browser anyway + # and will causes the resource load check to hang + link.attrib.clear() + changed.add(name) rewrite_links(root, partial(link_replacer, name)) for a in link_xpath(root): href = a.get('href') diff --git a/src/pyj/read_book/resources.pyj b/src/pyj/read_book/resources.pyj index d1266615a6..8743ed9af3 100644 --- a/src/pyj/read_book/resources.pyj +++ b/src/pyj/read_book/resources.pyj @@ -229,11 +229,13 @@ def unserialize_html(serialized_data, proceed): clear(document.head, document.body) load_required = set() proceeded = False + hang_timeout = 5 def hangcheck(): nonlocal proceeded if not proceeded: proceeded = True + print('WARNING: All resources did not load in {} seconds, proceeding anyway ({} resources left)'.format(hang_timeout, load_required.length)) proceed() def onload(): @@ -258,7 +260,7 @@ def unserialize_html(serialized_data, proceed): ev.initEvent('DOMContentLoaded', True, True) document.dispatchEvent(ev) if load_required.length: - setTimeout(hangcheck, 5000) + setTimeout(hangcheck, hang_timeout * 1000) else: proceeded = True proceed()