-1

I am trying to load my playlist onto my website from Spotify by using their API and requesting data by lines of AJAX code but that data would be loaded every single time if I refresh the page, which lower the speed and UX. Is there any solution of the problem?

P.S: a more complex problem: I was going to request the data once after period of time and modify the code of the HTML files stored on the server by a server-side Python application I wrote if any changes of the playlist occurred (example: I added/removed songs to or from my playlist via Spotify), for the purpose of not only freeing the browser from requesting datas but also getting the chances to sort that data by the date when publishing, rating or the artists for a better client-side layout. So my questions are:

  1. Is it secure to let the server-side applications to modify the HTML files (which means really saving the changes to the server-side HTML files) automatically because it is a very long process I don't want to either leaving those annoying works to the client-side which bothers the users or updating my website manually which bothers me.

  2. Are those things even possible?

halfer
  • 19,824
  • 17
  • 99
  • 186
  • is this for yourself only? or will many users be able to input their own playlist? – philz Apr 14 '15 at 05:10
  • For myself only, only I can modify the playlist. By the way, I saw your answer via my mibile app but for some creepy reasons I cannot comment it to give my highest compliment for your helpful answer. :) By the way, how about if I want to sort my songs by the artists in the alphabetic order? Is it gonna take lots of time if the work done by the browser? – Freddie Zhang Apr 14 '15 at 05:18
  • browsers will have no problem instantly parsing hundreds of json records from an ajax call. the majority of the time will be waiting for the ajax call to return – philz Apr 14 '15 at 05:24
  • how about if I call to not only Spotify but also Youtube and Flicker? – Freddie Zhang Apr 14 '15 at 05:28
  • the call timings will be relative to your internet connection (distance, speed), so its better to try it yourself and see if the timings are acceptable – philz Apr 14 '15 at 05:30
  • Having my highest compliment for serious – Freddie Zhang Apr 14 '15 at 05:31

1 Answers1

0

Try using html5 localStorage to store your playlist on the client's browser along with a timestamp. Once the timestamp is a certain period old, any loaded page can reload your playlist if necessary.

philz
  • 1,012
  • 6
  • 11
  • i would 2nd this, but with a twist: load the local version while booting and immediately dispatch a request to grab a new one. save that new one that comes in and reconcile and changes. – dandavis Apr 14 '15 at 05:27