Pregunta

this may seem like a strange question and I could have tested this first, but did not want to go through the hassle of setting it up only to find it doesn't work.

I have set up a JQuery based lightbox effect. The web page itself may be hosted at for example:

mysite.com

But I am not allowed to actually have access to the server for mysite.com (I know this sounds strange but it is what it is). However, I do have access to the server of a completely different website that belongs to the same organization. For example:

theirsite.com

So on a page where I want the lightbox effect to happen (mysite.com/lightbox.html) I can set up all of the tags and so forth on the page. But then in the head of this page, point to all of the JS and CSS files that are hosted on the theirsite.com server, so it looks like this:

So my question is - will this work? Or do I have to host all of the JS and CSS files on the same server (mysite.com) as the page itself that will display the lightbox itself?

Thanks.

¿Fue útil?

Solución

Yes, in fact jQuery hosts a copy of itself on a CDN available with this script inclusion tag:

<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>

CSS files can be included in a similar fashion, instead of a relative path use the absolute path (starting with http:// typically, or the double forward slash for shorthand).

Here's a pretty awesome CDN that hosts a ton of stuff.

Otros consejos

It will work fine, this is a very common practive and is encoraged in some situations.

For example, you should use the jQuery or google addresses for the jQuery libray, that way it can be cached on the client machine and used for several sites.

To verify, right click this page and view source, you'll see:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="//cdn.sstatic.net/Js/stub-uc.en.js?v=840de979f241"></script>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top