mercredi 29 avril 2020

Duplicate content generated(uuids, cached responses) javascript

For an ecommerce website we are building data registration object. For this we need te create uuid's of websessions. While building we seeme to generate a lot of duplicates. As a small test we build a small piece of code. This code however still gives a lot of duplicates.

        <script>
        (function () {
            var urlEndpoint = 'https://<url>/<endpoint>';
            var createXmlHttpRequest = function (url, settings) {
                var request = ('XMLHttpRequest' in window) ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP'); // eslint-disable-line no-undef
                request.open('POST', url);
                request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                request.send((settings.data || ''));
                request.onload = function () {
                    if (request.status >= 200 && request.status < 300 && typeof settings.callback === 'function') {
                        settings.callback('uuid=' + JSON.parse(request.response).uuid + '&timestamp=' + JSON.parse(request.response).timestamp);
                    }
                }
            };
            createXmlHttpRequest(urlEndpoint + '?getuuid=1&' + (new Date()).getTime(), {
                callback: function (data) {
                    createXmlHttpRequest(urlEndpoint + '?' + (new Date()).getTime(), {data: data})
                }
            })
        })();
    </script>

what we do is: - get a uuid from a backend script trough a post - pass that uuid back to another backend script and save it in a database

when doing this, we get al lot of duplicates in the second backend call. This does not make any sense to me, but maybe someone can shed a light and help us out.

This is by the way a high trafiic website with more then 2M view a day.

Also: the second call to save the uuid is for testing purposes. This will be removed and we will be using the uuid in the frontend




Aucun commentaire:

Enregistrer un commentaire