deferrender 404 error with txt file
deferrender 404 error with txt file
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?
Answers
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
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 emptyAnd i've added some htaccess lines, hope that compression is better now oO
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.
A description is available in the documentation:
deferRender
.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.
I would need a link to the page showing the issue.
Allan
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
The example file is 404:
If you want it to load
array.txt
then it needs anarray.txt
file :-)Allan
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
...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.
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?
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
which then gets used by DataTables with
What I have done in the AJAX example is removing the file_get_contents line and adding
in datatables. But the ajax response is emtpy. So I'm 100% sure that this file exists and is named "array.txt"
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
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
Why not call it
data.json
. That seems appropriate.Allan
Not working either
If that is also being blocked by your host, I would suggest contacting your host, or better a better one :-)
Allan
But the file does get loaded this time o:
Because you are loading a simply array of data (rather than an object with a
data
property) you need to tell DataTables this fact. Useajax.dataSrc
as an empty string to do so. Example.Allan