i am serving a static .html page to an iOS app with a uiwebview, and ~50% of the time, there will be a local .css file in the iOS app bundle which visually enhances the content of the served .html file. however, the other ~50% of the time, this .css file will simply not be there at all.
my concern is that this will delay the loading and display of the whole .html page, as it searches for the (missing) .css file which is referred to in the head, like so:
<link rel=stylesheet href=whatever.css>
are there any techniques that could be used to circumnavigate this issue? perhaps something related to javascript onerror would be useful, just to tell the page not to waste too much time looking, since if the file is there, it will be local, and available ~immediately.
thanks!
Related
So, I am copying a file hierarchy from a hosted application to my local machine. The hierarchy absurd, and after copying the http.conf file, the page loads, but not the JavaScript. It can't find the location.
Apparently there is some mechanism that overrides the DocumentRoot, like some sort of ad hoc routing.
I can't even find an .htacces file.
Is there anything in Apache that can suppress or alter the directives in http.conf?
Fixed this. In my case, the application was meant to load a custom filetype, but instead was loading the default .html because there was an index.html in the directory. Once I deleted the empty index.html the index.custom file loads.
I see this strange behavior (or may be I am missing something).
I have WebSphere 8.5. Deployed a EAR. Its working fine.
Instead of repacking and deploying every time for small change, I just copy the js and CSS files directly to the Websphere exploded folder and overwrite the existing files. I see the changes are getting reflected.
I just updated a JS file and added a couple jQuery functions and copied the file like above. Now when I refresh the page, I see the updated code (which is somewhere in the middle of the file). however the js file is not loading fully in all 3 browsers (IE8, Chrome and FF latest). It's getting cut off in the last 10 lines are so.
The file has 1784 lines. Not sure if there is a size limit on the browser side or WebSphere is tinkering with it or something else is going on. Any idea?
I did check the js file I copied to Exploded WebSphere folder. It has complete code.
Note that the page has a few more JS files (jQuery and other files) in addition to this one.
Edit:
I think WebSphere is keeping the size of the file somewhere (maybe?) and sending only that size every time, unless there is clean deploy or restart (?).
I removed a few lines of updated code. Now the browser loads, exactly that many number of additional lines of code. Once I remove my code completely, it loads the full file. (This is not an issue with the code though).
Is there a caching that I need to clear in WebSphere?
Check this page it Hot deployment and dynamic reloading. In general it says that you may need to restart the application.
Also check, if application reloading is enabled, however I'm not sure if it is relevant for static files.
If reloading of classes is enabled and the polling interval is greater
than zero (0), the application files are reloaded after the
application is updated. For JavaServer Pages (JSP) files in a web
module, a web container reloads JSP files only when the IBM extension
jspReloadingEnabled in the jspAttributes of the ibm-web-ext.xml file
is set to true. You can set jspReloadingEnabled to true when editing
your web module's extended deployment descriptors in an assembly tool.
You can restart app from console as provided in comments or via wsadmin script.
Here is the problem. The company I work for has a number of sites, and many of them use the same jQuery UI widgets, like datepicker. I would really like to have just one copy of each widget in an _javascript folder on the top level of the server. The problem is that because the code is outside of the site folder, I need to use ColdFusion mappings to point to it. Apparently you can't use these with script or link tags however. It doesn't expand the mapping. So I tried using "ExpandPath" and got a message that it doesn't have permission to access that resource. Some research turned up that JavaScript can't access files on local file systems because that would be a security hole. So, although it was ugly, I tried wrapping the CSS file in tags and the JS file in tags, and then included them with cfinclude. That worked- sort of. The main issue is that apparently the css uses relative links to link to the images used, and those are all broken because the JS is included on a page in another folder from the script and images themselves.
Here is my question. Is there any good solution here? I don't think that what I want to do is unreasonable, but should I give up and just keep a copy of the widgets in every site folder? Thanks in advance for any help.
Included javascript files, like CSS files, don't have to be touched at all by the ColdFusion processor. You just use ColdFusion to craft the link and feed it to the browser like you would any image, attachment, or link to another site. The only difference is that this link is in a <script tag. So if you have several sites and want to access a common /js directory on all of them the work has to be done in the web server itself (IIS/Apache).
In your web server of choice make a virtual directory (or symbolic link) to your javascript directory called /js (or whatever name you choose). Do this for all the sites, and you have one /js directory that is accessible from all the hosted domains.
My situation is that all our ColdFusion work is intranet only. While we only have a few sites, that is more than one. We also use a development server as opposed to having people develop on their hard drives.
The first thing we did was to create a mapping on "/" to point to a certain directory. Let's say that it's c:\fred. In c:\fred we have subdirectories named images, css, js, udf, etc. That allows us to do stuff like this:
<cfinclude template = "/Templates/Reportheader.cfm">
<link rel= "stylesheet" type= "text/css" href= "/css/cashflow.css" title= "style1">
<script type="text/javascript" src="/JS/browserDetect.js" ></script>
in any application.
I am a newbie, but I have spend the last 2 days reading so may things on this, and the more I read, the more confusing it gets. Not able to find one simple instruction or example to follow, or a simple and complete answer of this very important problem.
I simply want to include a common javascript file using src=. Then when I copy this tree to the server, I do not want to change anything in the code. I do not want to use relative path, since I do not want to edit the HTML file each time I change the tree layout. I want one solution that works when the tree is on the server, and also when it is locally on my PC during development.
I am not looking for something advanced or fancy. But a very simple solution. All what I want is to be able to use a common javascript file between all the HTML files I have in my tree.
The problem is that I do how to load it, since I can't use something like $HOME or ~ or an environment variable and so on, so that the same code works on my home PC, and also when I upload it to my personal web site.
To make it simple to answer this, I show the layout at my PC:
C:/public_html/common_files/common.js
C:/public_html/report/index.htm
On the server, say my site is called www.ABC.com, and I see, when I ftp to it, that there the public_html/ folder where I am supposed to put everything. So on the server, I created the same setup as above
/public_html/common_files/common.js
/public_html/report/index.htm
So far so good. Now the hard part.
How do I load common.js from index.htm file? I do not want to use src=../../common_files/common.js, why? Because I might want to change the layout of the tree, and if I move my report to another level, I do not want to edit it and keep changing the path and counting "../../../../.." etc..
I looked at many things, like ResolverURL but could not figure how to use it.
I tried
<script src="<%=Page.ResolveUrl("~/")%>public_html/common_files/common.js"></script>
But did not work. Remember, this has to work on the PC and on the server.
Here is my current index.htm.
<!DOCTYPE HTML>
<html>
<head>
<script src="../common_files/common.js"></script>
</head>
<body>
my site
</body>
</html>
To explain what I am looking for, assume for the moment that $HOME works in this env., which it does not offcourse, then I could have written
<!DOCTYPE HTML>
<html>
<head>
<script src="{$HOME}/common_files/common.js"></script>
</head>
<body>
my site
</body>
</html>
and this would have worked on the PC and on the server (well, at least it would work on a PC using linux). But the above is just an example of what I am looking for, on windows, I am not sure where $HOME is or how it is used if it is.
question: How to change the above src to load the common.js so that it works both on the PC and on the server but without using relative path?
Please do not give my more links to see, or partial answers, or ask me to download some commercial software to do this or complicated very advanced commands. This problem is so basic and the solution should be simple to follow.
By the looks of it, you seem to run your files locally on your PC. Try installing a server on your PC instead, to replicate the structure of your server. Something like XAMPP would do. On your server, the root of your domain would be the public_html. On a XAMPP setup, that would be the htdocs folder.
If you move files that much, then consider a location from the root of the domain, like a "styles" and "scripts" folder.
public_html/
'-- scripts/
'-- styles/
'-- everything else
Then load them with a leading /. The leading / means from the root of your domain.
<link href="/styles/your.css" type="text/css">
<script src="/scripts/your.js"></script>
<!-- similar to: -->
<link href="http://yourdomain.com/styles/your.css" type="text/css">
<script src="http://yourdomain.com/scripts/your.js"></script>
To prevent the comments turning into a very long conversation, I'll try to answer with some extra information.
Firstly, the term "absolute path" refers to the complete path of the file, as compared with the web root.
When you open files without an independant web server, the web root is the root of the drive you opened it from (in Windows this will usually start with the drive letter, but it can also just start with a slash).
This means, that unless you duplicate your entire drive to the hosting company (bad idea) you will usually need to run a web server to provide a web root that isn't the root of the file-system.
I understand that solutions such as XAMPP (which is awesome) are probably overkill if you only want to serve static pages (html, js, css, images etc.) that don't require any server-side processing, especially if you're running it on an aging laptop!
I've written (in Go) a very simple web server consisting of a single executable, around 3 or 4 MB in size, which will serve everything out of a folder named www on http://localhost by default. It also has command line switches to change the port from the default of 80, and to listen on more than just localhost. See http://github.com/Intermernet/ssws for details.
You can download the 64bit Windows version directly from https://github.com/Intermernet/ssws/blob/master/bin/windows_amd64/ssws_windows_amd64.zip?raw=true . If you require a 32bit version, tell me and I'll compile one for you, upload it and send you the link.
This should be saved somewhere on your local computer (Documents\WebDev or wherever) and then you just need to make a www folder in the same folder, and copy your website files into the www folder.
When you start (double-click) the exe file it will start serving your site files on localhost by default. If you don't want to start the server manually, put it in your Startup folder.
This will allow you to edit the files under the www folder and just refresh the browser to see the changes immediately.
Doing local web development without a local web server is possible, but has, as you've discovered, many pit-falls.
I hope you do manage to get this happening as I'd hate to see you lose faith or confidence in web development. These "sys-admin" tasks aren't really what programmers want to deal with, but sometimes they have to!
Also, when you get to the stage of trying to write dynamic server based code (PHP, Ruby, Python, Node.js etc.), you'll almost certainly need to ditch my simple server, and go with something like XAMPP.
Good luck!
I have a web page I run locally on a WebKit mobile browser (not on a web server) which has around 27 MB of JavaScript files, YES 27 MB of JavaScript files. It is because I have custom JSON objects and arrays hard-coded inside my .js file.
I have split the complete JS contain into 27 small .js files of around 1 MB.
The problem is that when I includes these .js files inside my header, the page load time increases very much.
I'd like to know how can I reduce the page load time in such a case where the js files are required.
1) Is there a way wherein we can inject the .js files inside the HTML after the page loads for the first time? (because the JavaScript content comes into picture only after a link is clicked on the page)
2) What would be an optimium solution to includes such a large JavaScript content inside a web page? I have minified my all js files to reduce the file size as much as possible!
Thanks in advance.
UPDATE 1:
The page runs locally and no WEB SERVER is involved. Finally, it would run inside a mobile browser, and so that's how all the problem arised i.e. the load timing is very high in mobile browser, so want to reduce the initial load time.
(Note: Most of the below was written before you'd bothered to tell us you were running an HTML file locally in a mobile browser without using a web server. Much of it still applies, some of it doesn't, but I've left it for others actually doing web pages.)
1) Is there a way wherein we can inject the .js files inside the HTML after the page loads for the first time?
Yes, it's actually really easy (live example: run / edit):
var script = document.createElement('script');
script.src = "path/to/the/file.js";
document.body.appendChild(script);
Note that the script will load asynchronously (you can't just assume it's loaded after the appendChild call).
But if your goal is just to have the page showing while the 27MB file downloads, you can just put your script tag at the end of your page, just before the closing </body> tag. Update: If you're running a local HTML file, not a web page, I'd think this is all you'd need: A single script tag at the end of the page loading your 27MB .js file.
2) What would be an optimium solution to includes such a large JavaScript content inside a web page?
Ideally, reduce the size if at all possible. If you can demand-load assets as you need them (either using the technique above or ajax), do that instead. Update: If you're running a local file, not a web page, you basically can't do ajax reliably. But you can demand-load what you need, when you need it, via adding script elements as per the above.
Regarding your 27 1MB .js files: If you hardcode the script tags for them, it's much better to do one 27MB file than 27 1MB files. Minimizing HTTP requests to your server (ideally at most one .js file and one .css file) is one of the key ways to improve page load time. In your case, though, you've said various parts aren't needed until various things are clicked, so you'll probably end up with a main file (which will hopefully be a lot smaller than 27MB), and then a bunch of other things you demand load (as per the above) as necessary.
Other things you can do:
Minify, compress, or "compile" your .js files (this means you'll have separate "source" and "production" files, since typically this is a one-way process that removes comments and such)
Ensure that your server is serving .js files with gzip compression (for instance, with Apache you'd use mod_deflate); you can test that it's working with various tools
Also very much worth a read: Best Practices for Speeding Up your Website, which makes the points above and a whole bunch more.
At 27MB it's always going to be slow as you're going to run into the memory limits on the device.
Most mobiles don't have a lot of RAM and once you load and parse the JSON it's going to be using more the 27MB
Minification will help you but gzip won't as the browser still has to decompress it)
If you're just rendering HTML in response to user actions, why don't you create HTML fragments instead of JSON and fetch these and insert them into the DOM when someone clicks on the link?
You have to combine again that *.js files into one. That will reduce the server requests that cost in time !
Compress your JavaScript content with that tool : http://www.refresh-sf.com/yui/ or that http://closure-compiler.appspot.com/home
Also you have to put that files at the page footer, in order to allow the page to be rendered while you download the js files into the client browser.
Another thing that can help is the long time caching of the file. This will allow your JavaScript to be "saved" into client web browser cache and next time is not important to re-downloaded.
Finally I am not 100% sure is that help but try lazy JavaScript loading.
Edit for Lazy Laod
<script type="text/javascript">
(
function()
{
var sc = document.createElement('script');
sc.type = 'text/javascript';
sc.async = true;
sc.src = 'http://www.url-to-your-javascript.file/my-javascript.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(sc,s);
}
)();
</script>
Another helpful source
http://gtmetrix.com/dashboard.html
Tests your web site speed. This will help you find your way on speed optimization about your web site :)
I would load the data after page load with ajax. That is after you loaded the page, you make an asyncronous request for the 27MB of data. This allows you also to eventually add a load animation while the data is transferred. You can have a look at jquery to implement this.
As a best practice, you should always load javascript in bottom oh html file. Put css at top, and js at bottom will greatly help.
27MB is too large. Why are you using hard code in js. you can use ajax. Take help from an expert, may be he can minimize your js
I finally solved over this problem of mine by creating a native application for the mobile device rather than using the hybrid (HTML5) technology i.e. I moved the 27 MB JS files which were containing the actual app data to an sqlite file and used it directly in my Android app.