在图像执行之前加载页面

时间:2022-10-12 15:34:56

I run Ruby threads that use PhantomJS, a command-line headless Webkit engine, to turn a number of urls into images. As of now, the page loads only once all of the images have been generated. Instead, I want to load the page and have a loading animation while the images are generated and show them as they are generated without the user having to reload the page. How would I do this? (I assume AJAX is needed.)

我运行使用PhantomJS(一种命令行无头Webkit引擎)的Ruby线程,将许多URL转换为图像。截至目前,只有在生成所有图像后才会加载页面。相反,我想加载页面并在生成图像时生成加载动画,并在生成图像时显示它们,而无需用户重新加载页面。我该怎么办? (我认为需要AJAX。)

2 个解决方案

#1


1  

You need to process them in a separate process. Once your request is finished, you lose a reference to the Threads that you started, so you can't just contact them again to ask for a progress report. I guess you could have the Threads write the result to the database once done, but there are better alternatives.

您需要在单独的过程中处理它们。一旦您的请求完成,您将失去对您启动的线程的引用,因此您不能再次联系它们以请求进度报告。我猜你可以让Threads在完成后将结果写入数据库,但有更好的选择。

Resque-status is a gem that extends Resque by allowing you to track the status of individual jobs. You queue the jobs and take their job IDs, then you can use AJAX to call back to the application and query the progress of those jobs.

Resque-status是一个宝石,通过允许您跟踪单个作业的状态来扩展Resque。您对作业进行排队并获取其作业ID,然后您可以使用AJAX回调应用程序并查询这些作业的进度。

#2


0  

Well, you could preload the images in the background, which would load up the page entirely while the images download.

好吧,你可以在后台预加载图像,这会在图像下载时完全加载页面。

more info: link

更多信息:链接

#1


1  

You need to process them in a separate process. Once your request is finished, you lose a reference to the Threads that you started, so you can't just contact them again to ask for a progress report. I guess you could have the Threads write the result to the database once done, but there are better alternatives.

您需要在单独的过程中处理它们。一旦您的请求完成,您将失去对您启动的线程的引用,因此您不能再次联系它们以请求进度报告。我猜你可以让Threads在完成后将结果写入数据库,但有更好的选择。

Resque-status is a gem that extends Resque by allowing you to track the status of individual jobs. You queue the jobs and take their job IDs, then you can use AJAX to call back to the application and query the progress of those jobs.

Resque-status是一个宝石,通过允许您跟踪单个作业的状态来扩展Resque。您对作业进行排队并获取其作业ID,然后您可以使用AJAX回调应用程序并查询这些作业的进度。

#2


0  

Well, you could preload the images in the background, which would load up the page entirely while the images download.

好吧,你可以在后台预加载图像,这会在图像下载时完全加载页面。

more info: link

更多信息:链接