0

I am building a simple website that will display some information. This information can be retreived from a third-party service and changes on average a couple of days.

Thus I need a way to dynamically generate my html files. I can see two alternative ways to do this and I don't know if one is better than the other.

  1. I create a script on my server, that periodically checks if the information changed on the third-party service and if it did edits the html markup accordingly and saves the file. Now when a visitor visits my site it will display the updated information

  2. I create a general html file that is sent to the visitor and use javascript to acess the third-party service and edit the markup accordingly.

Option 1 puts all the work on my server. Whereas option 2 makes the client browser to fetch the information.

Which option should be preferred and on which cases? What if the data is changing much more frequently?

closed as too broad by Stephen Ostermiller Feb 17 '18 at 11:43

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    How is the third-party service rate-limiting and policies? In first option it will get only your queries, so few of them, in the second one it will get as many queries as visitors to your site, so it could get overwhelmed plus your visitors can see from where you pick the information, which could be a problem or not. – Patrick Mevzek Feb 8 '18 at 16:12
  • all great points! In this case the third party is a simple google calendar, and the webpage I am building will, along other things, display information that depends on what next event in the calendar we have. This is a webpage for a non-profit so it is not an app that can have lots of users – gota Feb 8 '18 at 17:09
  • How does this third party license this content for you to use? The answer to this probably depends more on the sites terms of service than anything else. For example, YouTube allows you to use their embedded player but not use download the videos and re-host them. – Stephen Ostermiller Feb 17 '18 at 11:42
  • Another factor is SEO. Do you need this content and its keywords associated with your site? – Stephen Ostermiller Feb 17 '18 at 11:43
  • I've closed this as too broad because there are so many factors in this. If you edited this question to be just about calendar data, it would probably be narrow enough to answer. – Stephen Ostermiller Feb 17 '18 at 11:43
2

This information can be retrieved from a third-party service and changes on average a couple of days.

Since you know this info, you may want to perform your checks at that rate at most (once every couple of days). The best time to have such checks done are at the time where there will not likely be many guests on your site. This will minimize the amount of site-wide slowdowns.

What if the data is changing much more frequently?

Let it change but you have to consider the fact that when you're constantly fetching data from another server, you're putting a strain on their server, especially if you're trying to be a foreign bot who fetches a webpage once a second. I'd recommend not checking the site more than a few times a day and if your guests are anxious, consider adding a message to your site while letting them know when the next update will occur.

and do understand that scraping content from another website and trying to make it your own can get you in trouble with search engines because then you're asking for duplicate content to be indexed on the web.

Option 1 puts all the work on my server. Whereas option 2 makes the client browser to fetch the information. Which option should be preferred and on which cases?

Option 1 wins. In fact, use a server-side scripting language such as PHP to do all the back-end work and have it generate the HTML as well. On top of that, you can make the output compatible with all web browsers including new and old ones.

If you choose Option 2, then you're restricting full access to content to guests who have a powerful enough processor with the correct version of Javascript turned on in their web browsers. And if your code is too heavy in Javascript with too many new functions and/or unoptimized code, then it could slow down a guest's computer system.

0

Using file_get_contents to retrieve the page and file_put_contents with an expiry to store the page can do what you are requesting in PHP language.

You can use Javascript or AJAX to render the page from the remote server. But you should note that Google doesn't tend to count Javascript code on your page as content. And so any content that is rendered in Javascript is likely not to help you rank in the search results.

Not the answer you're looking for? Browse other questions tagged or ask your own question.