GWT offline, load json data in html - javascript

i got the following scenario. Im using GWT as an offline application. i stored my data as json in a js file and im including this js file in the html page of the GWT application. Im getting the included json data via jsni methods.
my Problem is, that when i use this offline (file://), the application has a very long startup time (ca 10 seconds at ~ 5mb json data file).
Interesing is, that when i put my application to a webserver and access my application there (http://), it loads without any loading time.
is there a difference in the file / http protocol when loading html files which include js files?
Is there a better way to use gwt offline with data?

If the data is static and is always needed in your app, you can use a TextResource instead of wrapping it in a JS file.

Related

Will multiple data files cause website to run slower, even if they aren't being used by web app?

Let's say I have a web application, and its function is to display data from a fairly large JSON file. The web page is one folder on my desktop (a data folder storing JSON files, HTML file, CSS folder storing CSS scripts, and JavaScript folder storing JS scripts) that I've pushed onto GitHub. Very straightforward.
"My application folder"
- css folder
-style.css
- data folder
-json1
-json2
-json3
-json4
-json5
-json6
- javascript folder
-main.js
-index.html
My question is this: will storing many large JSON files (each has different data) in the data folder cause my website to run slower, even if only one JSON is being rendered by the webpage at any given time? Does the loading time of the page increase if there's more data files in the data folder, regardless of whether they are actively being used by the web app and loaded into the DOM?
I'm asking because I'm thinking of storing many JSON files in the data folder, and dynamically loading different JSON files into the webpage based on what the user does. But - I don't want to use this approach if it's going to cause the webpage to load extremely slowly.
Yes - I know I could use a database in the cloud like PostGres, etc. But for now, I would like to avoid using a database if possible.
It will not slow your website because the files are not in use other then taking up space which could affect performance if the disks starts be coming full.

How can I get files and file names using JavaScript?

I am making a website that contains mainly static articles, and I wanted to just access .txt files from a directory and have the pages dynamically created that way when the site is loaded using JavaScript. However, I am struggling to find a way to get access to the files (The files would be in a folder wherever the site is being hosted along with the actual web pages and then I would be extracting the text from these files and creating the pages that way). Is this at all possible without having to use server side code or are there any recommendations for creating the pages another way? I would really like to avoid going through all of the trouble of continually adding html pages for every single article as that would be pretty monotonous and I currently don't have any back-end code and would like to keep it that way if possible. Any recommendations in general would be appreciated.
This is not possible without a backend server. Code running in browser is not allowed to access the files on the system due to security reasons.
Either write a simple backend service to fetch those text file or access those text file data by converting the text files as JavaScript files and declaring text data as variables. Then load these files before your main JavaScript file. Now you can access the data as variables in your main js script.
It is not possible in the traditional open file, read file and close file paradigm.
You could create a web service on your server that would return data from a file using ajax, such as the contents of the text file. But without any backend code, it will not be possible since there would be a lot of security implications if the client-side code was able to do so without any server-side code.

Upload files using angularjs without php script

just want to ask if it is possible to upload files (images, docs, pdf, etc.) using angularjs without actually using php script, instead all file uploads will use angularjs or javascript codes?. With this method i will be able to lessen the server load. Thanks
That is not possible.
AngularJS is solely a frontend framework. In order to upload something, you need to communicate with a server.

How to locate all images in a directory using jQuery

I'm developing an application which runs on a localhost server.! In this application I do ajax calls and get items from a local h2 DB! Using the response I create dynamic elements using jQuery. The elements use an item image as background and the requirement is that I should get the images from a local folder. ( The folder is created when the server is first started and the images are synchronized from a main server over the intranet. ) The folder hierarchy is shown below.
c:/----
|
zharaimages/ -----
|
[item id]/-----
|
[image].jpg
The image can contain any name for it but will be a jpg. How can I read the file system using jQuery to get the necessary image file when the item is dynamically loaded. I thought of this method but for that I can only read a file with a static name. I want to write a method where the image name can be anything.
clone.css('background-image','c:/zharaimages/' + items[i].itemId + '/image.jpg');
Any ideas or plugins are welcome.
Thank you.
update
This is a deployable application which uses an embedded jetty server. The folders are in the same computer as the application is!
Unfortunately a big NOOOOOO...
javaScripts cannot read or write files on users' computers (File API - not currently supported by many browsers - allows files to be read by scripts if the user specifically chooses to allow it),
though they can cause the browser to load remote pages and resources like scripts or images, which the browser may choose to cache locally.
They cannot create files on the server (except by communicating with a server side script that creates files for them).
You have to make a server request(many ways...) for the resources.
I'm not sure weather its possible with HTML5 or not
jQuery runs on the browser.
The files are on the server.
The only way that jQuery can read the files on the server is if it makes an AJAX call to the server, and your web server enumerates them.

Read local JSON file (no web-server) with JavaScript

It seems that this has been asked a number of times, but I would like to make sure there are still no other alternatives.
So what I need to do is:
Generate a .JSON file from .net (easy)
Read the local JSON file with JavaScript and produce an html page with useful graphs etc (using Raphaeljs).
Deliver the outcome (HTML + associated JavaScript) to the client.
I wouldn't mind installing a local Apache to read the JSON file easily but since I cannot ask the client to do this, I am looking for a way to read a local JSON file (on the filesystem, no web server) with JavaScript, so that I eventually provide the client with the HTML, .js and .json and he can see the associated graphs.
I 've been reading that FileReader class is an option but I want to have the flexibility to support these on a number of IE browsers (let say IE7 to IE10).
Any help on how to work round this would be much appreciated.
Web browsers are not able to read files from the file system due to security reasons. If I've understood correctly, you have a .NET application running on the local machine?
If this is the case, you can host a WCF service to serve the JSON from your application. WCF self-hosting is described on this MSDN page. You should be able to make AJAX requests from the browser to a server hosted within you application on localhost.
If you want to support older IE, you need to go into ActiveX Security setting hell. Look into var fso = new ActiveXObject("Scripting.FileSystemObject");
But if you are delivering the content and HTML files to the client, why don't you just add the JSON markup directly into the html document? Seems like the EASY solution.
You can't read file from local disk in browser (security restriction). But once you are going to deliver HTML + js and JSON (in zip?) you can read json like from regular web server. Just use relative links and if JSON will be in same folder where HTML and JS is located. Or you may put your JSON as a part of HTML you deliver to customer.
But if you are going to show a page (HTML and JS) on your site in web, you should better ask client to upload their JSON file, and than download it from server (in AJAX style).

Categories

Resources