简体   繁体   English

如何离线保存使用ember-cli-fastboot呈现的网页?

[英]How to save a webpage offline that is rendered with ember-cli-fastboot?

I am trying to save a webpage for offline viewing but not exactly having luck. 我正在尝试保存一个网页以供离线查看,但运气不佳。

The page is fairly intricate, as it involves javascript audio and video players, HTML embedded media. 该页面非常复杂,因为它涉及JavaScript音频和视频播放器,HTML嵌入式媒体。

On top of that, when I view the source I noticed ember-cli-fastboot comments and did some reading about it here: https://github.com/ember-fastboot/ember-cli-fastboot . 最重要的是,当我查看源代码时,我注意到了ember-cli-fastboot注释,并在此处进行了一些阅读: https : //github.com/ember-fastboot/ember-cli-fastboot So this ember-cli-fastboot seems to be all about server side rendering which for me I guess defeats the purpose of saving a website offline. 因此,这个ember-cli-fastboot似乎全都是关于服务器端渲染的,对我而言,我认为这违背了将网站离线保存的目的。

I have tried various Chrome extensions such as Save Page WE , WebScraper . 我已经尝试过各种Chrome扩展程序,例如Save Page WEWebScraper They get me fairly close, with text, images, and the basic structure of the page looking fine, but the flash and JS-based players are not loading . 它们使我与文本,图像和页面的基本结构看起来相当接近,但是Flash和基于JS的播放器未加载

I also tried downloading the page in Chrome Developer Tools using Save All Resources extension, but that seems to produce similar result to what I get with Save Page WE , namely all text and images are loaded but audio and video players don't load. 我还尝试使用“ 保存所有资源”扩展程序在Chrome开发人员工具中下载页面,但这似乎产生了与“ 保存页面WE”相似的结果,即所有文本和图像均已加载,但音频和视频播放器未加载。

Here is an example snippet of code for one of the players: 这是其中一个播放器的示例代码片段:

<div id="area49254180_6" class="component interaction_component float-none clear-none hideSlideshowControls interaction_booted"><div role="status" class="int-prep hidden"><i aria-hidden="true" class="fa fa-circle-o-notch fa-spin fa-3x fa-fw"></i><br> Loading interaction...</div><div>
<div class="data-field interaction-type">Slideshow</div>
<div class="data-field interaction-init">
<span class="field">jplayer_swf_path</span><span class="value"><a target="_blank" href="https://dvgddacn5gars.cloudfront.net/691v.swf?response-content-disposition=inline%3Bfilename%3D%22Jplayer.swf%22&amp;Expires=2147483647&amp;Signature=BUOmjigHUL9go1MM~SvrLXLDR8gJZzCVKEUrXoUw~49Qn4g54HUK3nQpFpLUD8IXZiuv3ygkyqcxNMdhZg1V2g4DnvIql-tnGGZ2E1Kdyz3c6SIfbNx-LZasBf5M9jvoXFYGqEtugXZV0etgoGrL9CRV0Xnwn~Ee09DCrzdRPLQ_&amp;Key-Pair-Id=APKAIVZN4AJ762UIENTQ">https://dvgddacn5gars.cloudfront.net/691v.swf?response-content-disposition=inline%3Bfilename%3D%22Jplayer.swf%22&amp;Expires=2147483647&amp;Signature=BUOmjigHUL9go1MM~SvrLXLDR8gJZzCVKEUrXoUw~49Qn4g54HUK3nQpFpLUD8IXZiuv3ygkyqcxNMdhZg1V2g4DnvIql-tnGGZ2E1Kdyz3c6SIfbNx-LZasBf5M9jvoXFYGqEtugXZV0etgoGrL9CRV0Xnwn~Ee09DCrzdRPLQ_&amp;Key-Pair-Id=APKAIVZN4AJ762UIENTQ</a></span>
</div>
<div class="data-field interaction-asset">
<span class="field">audio_track</span><span class="value"><a target="_blank" href="https://dvgddacn5gars.cloudfront.net/5fkk.mp3?response-content-disposition=inline%3Bfilename%3D%22L01_Diatonic-Chords-1.mp3%22&amp;Expires=2147483647&amp;Signature=SGmoFTa4sBtiuDqCS0v9A5Qv6y7Q-3PftkRN6Eu3DbxhTqMLbmEhwA4~oXuaRw0BprkB8MbockpY3AhQwEUxWxVOrQE1WO9Wb-riZxHtygYphEpYcbn9eZ4Bp02u-4nM820PsOxqvWJ~-9Fovk7IFu1LAmZ-aG9vWptqPo5Ke-8_&amp;Key-Pair-Id=APKAIVZN4AJ762UIENTQ">https://dvgddacn5gars.cloudfront.net/5fkk.mp3?response-content-disposition=inline%3Bfilename%3D%22L01_Diatonic-Chords-1.mp3%22&amp;Expires=2147483647&amp;Signature=SGmoFTa4sBtiuDqCS0v9A5Qv6y7Q-3PftkRN6Eu3DbxhTqMLbmEhwA4~oXuaRw0BprkB8MbockpY3AhQwEUxWxVOrQE1WO9Wb-riZxHtygYphEpYcbn9eZ4Bp02u-4nM820PsOxqvWJ~-9Fovk7IFu1LAmZ-aG9vWptqPo5Ke-8_&amp;Key-Pair-Id=APKAIVZN4AJ762UIENTQ</a></span>
</div>
<div class="data-field interaction-asset">
<span class="field">images</span><span class="value"><a target="_blank" href="https://dvgddacn5gars.cloudfront.net/5fkj.xxx?response-content-disposition=inline%3Bfilename%3D%22L01_Diatonic-Chords-1.xxx%22&amp;Expires=2147483647&amp;Signature=inxGPaQkl-beyoR2OG8bOSLXCekpyWf4G6XmHq3KCgEV8qWDLJM5-ThWnI9hI~-nh8TtyrqsC8ZNYN3iWh~0U5zrzNfgw~8F96hhNmJuvsRyFWb33~yXyQVjSlBmKbrHd-qxa~tSm00W-ViBnNIMuQw1AVIy8uiZSSWwAiPnCTU_&amp;Key-Pair-Id=APKAIVZN4AJ762UIENTQ">https://dvgddacn5gars.cloudfront.net/5fkj.xxx?response-content-disposition=inline%3Bfilename%3D%22L01_Diatonic-Chords-1.xxx%22&amp;Expires=2147483647&amp;Signature=inxGPaQkl-beyoR2OG8bOSLXCekpyWf4G6XmHq3KCgEV8qWDLJM5-ThWnI9hI~-nh8TtyrqsC8ZNYN3iWh~0U5zrzNfgw~8F96hhNmJuvsRyFWb33~yXyQVjSlBmKbrHd-qxa~tSm00W-ViBnNIMuQw1AVIy8uiZSSWwAiPnCTU_&amp;Key-Pair-Id=APKAIVZN4AJ762UIENTQ</a></span>
</div>
<div class="data-field interaction-init">
<span class="field">initial_json</span><span class="value">[{"imageIndex":0,"time":0,"rect":null}]</span>
</div>
<div class="interaction_title"></div>
<div class="interaction_content Slideshow" style="min-height: 50px; width: 400px;"><div id="ember7214" class="ember-view"><div class="slideshow-jplayer" id="slideshow_player_49254180_6"></div>
<div class="slideshow-player">
  <audio class="player" src="https://dvgddacn5gars.cloudfront.net/5fkk.mp3?response-content-disposition=inline%3Bfilename%3D%22L01_Diatonic-Chords-1.mp3%22&amp;Expires=2147483647&amp;Signature=SGmoFTa4sBtiuDqCS0v9A5Qv6y7Q-3PftkRN6Eu3DbxhTqMLbmEhwA4~oXuaRw0BprkB8MbockpY3AhQwEUxWxVOrQE1WO9Wb-riZxHtygYphEpYcbn9eZ4Bp02u-4nM820PsOxqvWJ~-9Fovk7IFu1LAmZ-aG9vWptqPo5Ke-8_&amp;Key-Pair-Id=APKAIVZN4AJ762UIENTQ"></audio>
  <div class="audio-controls">
    <i class="fa fa-play playpause"></i>
    <i class="fa fa-pause playpause inactive"></i>
    <input id="player-seek" type="range" min="0" max="100" value="0" onchange="">
    <i class="fa fa-retweet loop"></i>
  </div>
</div>
<div class="controls fr hidden">
  <i class="fa fa-arrow-circle-left back"></i>
  <span class="pages">1 of 1</span>
  <i class="fa fa-arrow-circle-right forward"></i>
</div>

<div class="page_container">
  <div class="highlight hidden"></div>
  <div class="image-area"><immg src="https://dvgddacn5gars.cloudfront.net/5fkj.png?response-content-disposition=inline%3Bfilename%3D%22L01_Diatonic-Chords-1.xxx%22&amp;Expires=2147483647&amp;Signature=inxGPaQkl-beyoR2OG8bOSLXCekpyWf4G6XmHq3KCgEV8qWDLJM5-ThWnI9hI~-nh8TtyrqsC8ZNYN3iWh~0U5zrzNfgw~8F96hhNmJuvsRyFWb33~yXyQVjSlBmKbrHd-qxa~tSm00W-ViBnNIMuQw1AVIy8uiZSSWwAiPnCTU_&amp;Key-Pair-Id=APKAIVZN4AJ762UIENTQ"></div>
</div>
</div></div>
<div class="interaction_data" style="display: none;"></div>
</div></div>

Notice in the first div element above, this text: "interaction_booted" in the class name. 注意,在上面的第一个div元素中,该文本为:类名中的“ interaction_booted”

This seems to be the key to what is happening . 这似乎是正在发生的事情的关键 When I save the page and then load it, using one of the methods I mentioned above, I see this in that first div element (corresponding to what I pasted above): 当我保存页面然后使用上面提到的一种方法加载它时,我在第一个div元素中看到了这一点(与我上面粘贴的内容相对应):

<div id="area49254180_6" class="component interaction_component float-none clear-none hideSlideshowControls"><div role="status" class="int-prep"><i aria-hidden="true" class="fa fa-circle-o-notch fa-spin fa-3x fa-fw"></i><br> Loading interaction...</div>

So we no longer see "interaction booted" in the class name. 因此,我们不再在类名中看到“交互已启动” So anytime I open saved versions of this page, the javascript seems to be making some sort of check and is then not loading the content, and instead replaces the element along the lines of what you see in the above code snippet. 因此,每当我打开此页面的保存版本时,javascript似乎都在进行某种检查,然后不加载内容,而是按照上面代码片段中的内容替换该元素。

Now, I am not a developer. 现在,我不是开发人员。 I have done some PHP coding and am fairly technical at this stuff for a non dev, but hey I am a guitarist first and foremost and I am definitely out of my technical league trying to figure this out... 我已经做了一些PHP编码,并且对于非开发人员来说,在这方面是相当技术的,但是嘿,我首先是吉他手,而且我绝对不在我的技术联盟中试图解决这个问题...

Really curious how you experts would go about saving this sort of content for offline viewing, such that all resources are saved offline, with no need for server side rendering. 真的很好奇您的专家将如何保存此类内容以供脱机查看,以便所有资源都脱机保存,而无需服务器端渲染。 If it requires some custom scripting, I could probably handle it, just need to understand the general idea. 如果它需要一些自定义脚本,我可能可以处理它,只需要了解一般的想法即可。

Thanks! 谢谢!

Brian, what you're looking for is something called service workers. Brian,您正在寻找的是所谓的服务人员。 You have to setup service workers on your project to make the contents visible offline. 您必须在项目上设置服务工作者,以使内容脱机可见。

Service workers run on your browser and as soon as you make a Server call, your service worker will cache the response and serve it to you. 服务人员在您的浏览器上运行,并且在您发出服务器调用后,服务人员将缓存响应并将其提供给您。 Because of the server responses being cached by the browser, when there's no internet, the API calls are intercepted by the SW and the cached response is returned. 由于服务器响应是由浏览器缓存的,因此当没有互联网时,SW会拦截API调用,并返回缓存的响应。

You can use this awesome plugin by Dockyard to setup service workers on your project to start with. 您可以使用 Dockyard的这个很棒的插件在您的项目上设置服务工作者。 🙌 🙌

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM