Mobile app version of vmapp.org
Login or Join
Courtney195

: When to render/build my html that changes frequently? I am building a simple website that will display some information. This information can be retreived from a third-party service and changes

@Courtney195

Posted in: #Clients #Javascript #Server #Webserver

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.


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
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?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Courtney195

2 Comments

Sorted by latest first Latest Oldest Best

 

@Steve110

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.

10% popularity Vote Up Vote Down


 

@Harper822

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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme