deferrender 404 error with txt file

deferrender 404 error with txt file

InnerwolfInnerwolf Posts: 24Questions: 4Answers: 0

Hey,

currently everything with my page is working fine but loading times are still longer than i wished. The page needs a couple of seconds to load with good internet connection and way too long with a bad one. I already inserted a loading animation to distract the user and added some new .htaccess options so that the browser can store some static data but I really want to speed things up with the deferrender option and I don't want to store the whole php array to a database.

Only problem is that the ajax request fails and gives a 404 error. array.txt is a json encoded php array (file_put_contents(".../array.txt", json_encode( $array ));), that gets renewed each hour and is in the same dir as the html and the js file..

table = $('#scoreboard').DataTable({
        "ajax": "array.txt",
        "deferRender": true,
        //....
}

Has it something to do with the server settings, i.e. that txt can't be accessed that way (I also can't open any txt file in the browser through the usual link)? Should I save the array in another file format? How?

Thanks! http://zcatch-ranking.host56.com/

Answers

  • allanallan Posts: 63,360Questions: 1Answers: 10,448 Site admin

    That's some long loading! It is taking about 7 seconds to load on my connection - the data size being about 1MB. That seems like a very long time to me for that data - is the server on a slow uplink?

    I would suggest adding the deferRender option (it is currently commented out), but that isn't going to speed things up much since that isn't the main slow part - its the loading of the data.

    Your server doesn't appear to be using gzip - I would suggest looking into that to help improve download times.

    I would also suggest using the minified version of DataTables, rather than loading all of the debug version.

    Allan

  • InnerwolfInnerwolf Posts: 24Questions: 4Answers: 0
    edited August 2015

    Wouldn't ajax-load the data help? I mean what exactly does deferrender? I thought of it as data splitter, where only the requiered data gets downloaded and not the whole array. The problem with deferrender, as i've mentiones, is that the "ajax": "array.txt" response is empty

    And i've added some htaccess lines, hope that compression is better now oO

  • allanallan Posts: 63,360Questions: 1Answers: 10,448 Site admin

    Ajax loading would help the initial load time - but it wouldn't help the overall time, since the same amount of data still needs to be loaded.

    I mean what exactly does deferrender?

    A description is available in the documentation: deferRender.

    I thought of it as data splitter, where only the requiered data gets downloaded and not the whole array

    No. There is server-side processing which basically does that, but it will not work with a plain text file. You need to do processing at the server-side. See the manual for details.

    The problem with deferrender, as i've mentiones, is that the "ajax": "array.txt" response is empty

    I would need a link to the page showing the issue.

    Allan

  • InnerwolfInnerwolf Posts: 24Questions: 4Answers: 0
    edited August 2015

    Thanks for the tips so far. Here an example page: http://zcatch-ranking.host56.com/ajax.htm

    Does server-side require a (sql) database?

    p.s.: I've activated gzip now! http://fs1.directupload.net/images/150810/zwom73ke.png

  • allanallan Posts: 63,360Questions: 1Answers: 10,448 Site admin

    The example file is 404:

    $ curl -I http://zcatch-ranking.host56.com/array.txt
    HTTP/1.0 404 Not Found

    If you want it to load array.txt then it needs an array.txt file :-)

    Allan

  • InnerwolfInnerwolf Posts: 24Questions: 4Answers: 0

    There is an array.txt file in the same directory, as i've said in my question! it gets loaded in the html file with file_get_contents

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    it gets loaded in the html file with file_get_contents

    ...except it doesn't get loaded because file_get_contents() can't find it.

    You are the only person who knows what your file system paths look like.

  • InnerwolfInnerwolf Posts: 24Questions: 4Answers: 0

    it obviously does get loaded because otherwise the table wouldn't be shown, which isn't the case. so the file can be found. I just deactivated this line because i wanted to ajax load it, was this the mistake?

  • InnerwolfInnerwolf Posts: 24Questions: 4Answers: 0

    Once again: I'm using PHP to convert a csv file to an array. This array gets json_encoded and stored with file_put_contents as "array.txt" in the same directory as the htm and the js file. Currently, The HTML file grabs the array data with

    <script type="text/javascript">
        var array = <?php echo file_get_contents("array.txt") ?>;
    </script>
    

    which then gets used by DataTables with

    $('#scoreboard').DataTable({
        "data": array,
        ....
    }
    

    What I have done in the AJAX example is removing the file_get_contents line and adding

    $('#scoreboard').DataTable({
            "ajax": "array.txt",
            "deferRender": true,
            ....
    }
    

    in datatables. But the ajax response is emtpy. So I'm 100% sure that this file exists and is named "array.txt"

  • allanallan Posts: 63,360Questions: 1Answers: 10,448 Site admin

    The URL you are giving DataTables resolves to be http://zcatch-ranking.host56.com/array.txt. That's fine - if there were a file there. There is not, or the server is setup to not allow access to it.

    Try clicking this link in your browser: http://zcatch-ranking.host56.com/array.txt . It is 404.

    So yes, the file is obviously somewhere since your PHP is using it, but either it is somewhere else in the file system, or the web-server won't allow access to it, since, as I stated above, the file is 404 at the URL that is being used.

    Allan

  • InnerwolfInnerwolf Posts: 24Questions: 4Answers: 0

    Okay I tried saving it as array.js or something since txt files seems to be restricted by the hoster. But it doesn't seems to load properly: http://zcatch-ranking.host56.com/array.txt

  • allanallan Posts: 63,360Questions: 1Answers: 10,448 Site admin

    Why not call it data.json. That seems appropriate.

    Allan

  • InnerwolfInnerwolf Posts: 24Questions: 4Answers: 0

    Not working either

  • allanallan Posts: 63,360Questions: 1Answers: 10,448 Site admin

    If that is also being blocked by your host, I would suggest contacting your host, or better a better one :-)

    Allan

  • InnerwolfInnerwolf Posts: 24Questions: 4Answers: 0

    But the file does get loaded this time o:

  • allanallan Posts: 63,360Questions: 1Answers: 10,448 Site admin

    Because you are loading a simply array of data (rather than an object with a data property) you need to tell DataTables this fact. Use ajax.dataSrc as an empty string to do so. Example.

    Allan

This discussion has been closed.