Best practice for on/off line data synchronization using AngularJS and Symfony 2

前端 未结 5 1653
情书的邮戳
情书的邮戳 2021-01-31 11:38

I\'m building a relatively complex and data heavy web application in AngularJS. I\'m planning to use php as a RESTful backend (with symfony2 and FOSRESTbundle). I have spent wee

5条回答
  •  -上瘾入骨i
    2021-01-31 11:52

    To work offline with your requeriments I suggest to divide problem into two scenarios: content (html, js, css) and data (API REST).

    The content

    Will be stored offline by appcache for small apps or for advanced cases with the awesome serviceworkers. Chrome 40+.

    The data

    Require solve the storage and synchronization and It becames a more difficult problem. I suggest a deep reading of the Differential Synchronization algorimth, and take next tips in consideration:

    Frontend

    Store the resource and shadow (using for example url as key) into the localstorage for small apps or into more advanced alternatives (pouchdb,indexdb,...). With the resource you could work offline and when needs synchronize with the server use jsonpath to get diffs between the resource-shadow and to send it to server the PATCH request.

    Backend

    At backend take in consideration storage the shadow copies into redis.

    The two sides (Frontend/Backend) needs to identify the client node, to do so you could use x- syn-token at HTTP header (send it in all request of the client with angular interceptors).

提交回复
热议问题