• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Having trouble loading JavaScript file

 
Vipul
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can i include a ASP file in a JSP file ???

<script type="text/javascript" src="/includes/NewMainHeader.asp"></script>

what are the implications of the above ....
[ August 10, 2006: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65126
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not really what I would term an "include".

The fact that the page is a JSP is completely moot. By the time the browser gets the page, it's just an HTML page as far as the browser is concerned.

So it will reference the asp file as a script file just like any HTML page would.

This, of course, assumes that your app server is capable of handling both JSP and ASP.
[ August 10, 2006: Message edited by: Bear Bibeault ]
 
Vipul
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for a quick reply

I am using Webshpere 5.1 as my app server . so i dont think it is able to handle asp request .
But tried adding the above code in my jsp ...it works it is able to get the script ....


Actually i need to include a javascript to get a header in my app .
When i include the javascript its shows me a security pop up saying that its trying to access a file that is out of this website control.
and in forefox it dont even shows the javascript
( the javascript file i am trying to inlcude is trying to use a XML file from a diff server )

i found this explanation for the error ...i dont if thats the one
(http://www.mozilla.org/projects/security/components/same-origin.html)




So I included the same file as a ASP file ..all works fine ...I am not sure if thats a good idea ....

I am not sure i have explained it properly ...

Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65126
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vish pat:

When i include the javascript its shows me a security pop up saying that its trying to access a file that is out of this website control.


Is the JavaScript file being referenced from another server?

If not, I'd spend my time trying to find out why the browser is unhappy with your reference. You should be able to reference any JS resources on the same server without issue.

Resorting to asp to get around this issue is sort of like saying "my car won't start, so I tied it to the back of a bobsled" instead of finding out why it won't start. Fix the real problem rather than resoirting to work-arounds which are likely to introduce problems of their own.

Also, since this isn't JSP related at all, I've moved it to the HTML/Javascript forum with an appropriate change of title.
 
Vipul
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are correct ..its not a good idea to include a ASP ...

the javascript that i need to include is on another server ..



the security pop up that i get says "This page is accessing information that is not under its control / This poses a security risk.Do you want to continue?"

I think this is the due to "cross-domain security" problem of script accessing a resource our of its domain (other domain name )

Do you have any workaround for this ??


Thanks for moving the post to the correct forum i will take care in future .
[ August 10, 2006: Message edited by: vish pat ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65126
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why cannot you just make a local copy of the JS file?
 
Vipul
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that js file is used by large amount of appication in the organization ..so it have to be maintained on the single server ....

this js has reference to two xml files while are on the same server as the js file ...

do we have a workaround ??
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65126
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vish pat:
that js file is used by large amount of appication in the organization ..so it have to be maintained on the single server


No, it doesn't have to be. This type of sharing should be handled at build time, not by run-time hacks.

A single copy of the file in source control should be copied into each web app when the app is being built. Web apps should be self-contained and not have such inter-dependencies.
 
Vipul
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But that defeats the whole purpose of code reuse and code mantainability .....if something makes changes in the js file..then every web app that is using it needs to rebuild and redeployed.

I believe in most of the organizations , to make the look and feel of the web app similar ...they have certain includes that are kept on a central server for use .

Thanks
[ August 10, 2006: Message edited by: vish pat ]
 
Vipul
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have decided that including the asp in our application is the only resolution. The assumptions and reasons behind this are

Reasons
1)The including of just the javascript in our application has a cross site security issue. The reason behind it is the Javascript when executing tries to read a xml file which is in a different domain(buy vs buy-it)
2)The only way to overcome this is by changing the internet option to allow download across domains. This is not possible and I do not think anyone should be forced to take this risk just to get a quote from our site however good the site may be.

Assumptions
The included asp file will always deliver to us javascript. i.e. MIME text/javascript. This is a very important assumption because we will not be able by the nature of our container do any additional responsibilities
 
Vipul
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vish pat:
I have decided that including the asp in our application is the only resolution. The assumptions and reasons behind this are

Reasons
1)The including of just the javascript in our application has a cross site security issue. The reason behind it is the Javascript when executing tries to read a xml file which is in a different domain(buy vs buy-it)
2)The only way to overcome this is by changing the internet option to allow download across domains. This is not possible and I do not think anyone should be forced to take this risk just to get a quote from our site however good the site may be.

Assumptions
The included asp file will always deliver to us javascript. i.e. MIME text/javascript. This is a very important assumption because we will not be able by the nature of our container do any additional responsibilities


Any better approaches are welcome ..
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vish pat:
Any better approaches are welcome ..
Okay. But why ASP? You could write a servlet to deliver a javascript file. Servlets are a technology you already have, whereas ASP is a totally new technology that places additional requirements on your server and on your programming staff.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65126
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vish pat:
But that defeats the whole purpose of code reuse and code mantainability


It most certainly does not. There is one copy of the shared file(s) in source control. Perfectly re-usable and perfectly maintainable.


.....if something makes changes in the js file..then every web app that is using it needs to rebuild and redeployed.


So you are telling me that you deploy your apps without testing?

In your shared scenario, a change to the JS file on the single server that introduces a bug will break all of the web apps. Bad, bad idea.

Any change to the shared file should cause all apps to be re-built, re-tested and re-deployed. Anything else is a disaster waiting to happen.


I believe in most of the organizations , to make the look and feel of the web app similar ...they have certain includes that are kept on a central server for use .


Most certainly not any that I have worked at. The central point of sharing is the source control system, not a live run-time server.
[ August 11, 2006: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65126
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vish pat:
I have decided that including the asp in our application is the only resolution.


It's your foot...
 
Vipul
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The whole point of having dynamic resources is avoiding your app to rebuilt and redeploy due to a change in the peice of code which is prone to change frequently.

Testing your code after changes any code (dynamic resources included) is implied.

"Any change to the shared file should cause all apps to be re-built, re-tested and re-deployed"

I dont think this quote sounds correct from architectural point of view of a web app which has many dependencies on other apps or resources .


I am not pro architect ....so please correct me if i am wrong.


Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65126
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vish pat:

I dont think this quote sounds correct from architectural point of view of a web app which has many dependencies on other apps or resources .


A web app shouldn't have any dependencies outside of itself other than those that cannot be avoided (reliance on a Google or Yahoo API, for example).

All internal dependencies, like your shared JavaScipt file, should be shared in the source control system and your web apps should be independently built, tested and deployed without relying on run-time dependencies.

Otherwise, you have no real control over your deployed systems.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic