Knowledgebase: Documentation
Best Practice Method to Get Screenshot Requests as Soon as Ready
Posted by Brandon Elliott on 13 August 2016 01:19 AM

Do you want to show a web page screenshot to your users the instant it is ready?

Do you want to use something like Ajax to continuously check for ready state?

Do you want to avoid being charged for constantly polling with excessive requests to ShrinkTheWeb to check for ready state?

 

This article addresses all of these questions. Some users have hammered this service with requests every 1-2 seconds (or even more than once per second), checking to see if a screenshot is ready. That is excessive and uses up costly resources. So, we pass those costs on to the customer in the form of bandwidth charges for each hit. However, it is not our intention to make money this way but rather to pass along costs for integrations that are not ideal. However, we prefer that users follow the "Best Practice" method below and save us AND themselves, time, money and frustration; while simultaenously improving their user's experience. ;)

Consideration #1: Security

If you are using jQuery/AJAX/etc or any "in-browser" code to poll our service, then you or your users may be facing cross-domain security issues. All of this is overcome by using a "middleman" or "proxy" script on your domain to make the initial request and provide status to your "checker" script.

Consideration #2: Keeping costs low

To avoid racking up unnecessary bandwidth charges, all integrations should rely on our "Notify Callback" feature to quickly deliver screenshots when ready and use local placeholders to designate request status. See below for an example.

Consideration #3: Getting screenshots as soon as ready

Our "Notify Callback" workers are constantly delivering or notifying users of screenshots that are ready. Typically, a "Notify" worker will notify of a ready capture in less than 1 second. Under extremely heavy load, there may be delays, so we recommend having a fallback check once every 20-30 seconds, just to be certain. This secondary check is not handled in our sample code.

Please note that if the screenshot is already READY, then we will ignore the CALLBACK request, because it is quicker, and less work on both sides, for you to just go ahead and download the image immediately. The process would be to parse the XML response of your request, every time, and if the status is "delivered" (image download URL will be provided), then go ahead and download the image. This is handled automatically in the sample code, but if making a custom integration; it is important to recognize this additional step.

Note: If this extra step, when READY, causes undue work to integrate, let us know. I am not opposed to adding an override to always push the image (in case it simplifies development).

Consideration #4: Figuring out the code

Fortunately, we went through the trouble of doing all of this ourselves, using our Snapito screenshot demo site to get a feel for creating a great user experience. We include an example script in our sample PHP code to help you get started or use as a guide for converting to another programming language. We also provide a basic jQuery example to help get you started there as well.

 

An example of a "Best Practices" integration (all handled in our sample PHP code & Javascript/Ajax sample found on our ShrinkTheWeb Integrations page):

  • Use jQuery/AJAX/etc to send a request to the "middleman" script on your domain
  • Let the middleman script make the initial request and create a local file placeholder (like filename123-queued)
  • Follow-up checks will trigger the middleman script to check for the queued placeholder and report back "not ready" state, if it exists
  • As soon as the request is ready, ShrinkTheWeb's "Notify" workers will deliver it and the remote "Notify" receiver will put the screenshot image and delete the "queued" placeholder
  • The next follow-up check will find that there is no queued placeholder and checks the local disk for the screenshot image and report that it's ready
  • Since your scripts know where you store the delivered images and the filename convention, it may work with the screenshot image
  • As a precaution for error conditions, it is recommended to also "clean up" any queued placeholder that is more than 120 seconds old

 

Related terms: callback notify notification screenshot delivery

(0 vote(s))
Helpful
Not helpful

Contact Us | PagePix Benefits | Learn More | STW Forums | Our Partners | Privacy Policy | Terms of Use

©2016 ShrinkTheWeb. All rights reserved. ShrinkTheWeb is a registered trademark of ShrinkTheWeb.