Friday, 5 January 2007

Reference JavaScript from the File System in Application Express

The strangest thing happened the other day whilst performing an application import within Oracle XE. The import was successful but running the application however was less so.

Some of my pages contained a lot of JavaScript in the HTML Header section of the Page Attributes. On some of these pages, the import appeared to add a carriage return to one of the lines and thus breaking my script. The knock on effect was that my application ground to a rather unimpressive halt.

Without having the time to investigate why, I decided that it would be better to store all my JavaScript in a .js file on the server and write a reference to it on the pages where the scripts were needed.

Once you have created your .js file (I store in a sub directory if the /i/ path) on the server, you can reference these files by adding the following to the HTML Header of your page:

Storing your long JavaScript externally to your application also makes debugging a bit easier as well.

No comments: