[Question] share javascript to other domain

  • epoy
  • Newbie
  • Newbie
  • epoy
  • Posts: 13
  • Loc: Phillipines

Post 3+ Months Ago

How can I share a javascript file from
Code: [ Select ]
js·mydomain·com to mydomain·com.

The idea is I want a sub domain to handle my javascript files.

How do google and facebook share their javascript library to the whole world?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

If you have a look at the html files you will see thay have include statements pointing to the url of the javascript library. Right click their pages and you will see it inside a script tag.

Code: [ Select ]
<script type="text/javascript" src="http://www.domain.com/cheese.js"></script>


Code: [ Select ]
<script type="text/javascript" src="http://sub.domain.com/cheese.js"></script>


These are jsut the references. Due to the fact that the javascript is executed client side, if you wanted to share javascript objects between page requests you woul have to serialize the data and pass it back to the other domain/page via a service mechanism of sorts.

JSON seems to be the standard mechanism for serializing objects lately and would probably work ok for you.

Another thing to remember is that you can have all your objects defined in the library located at js.domain.com and the functions defined in the library located at mydomain.com and have them all work together on the same page. Just make sure you import the dependancies first :)
  • epoy
  • Newbie
  • Newbie
  • epoy
  • Posts: 13
  • Loc: Phillipines

Post 3+ Months Ago

My problem is the "Same Origin Policy for Javascript"
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

Ah sounds like you running into a cross domain scripting issue. Not the way you described it.

I think you going to have to figure out how to get round cross domain scripting calls. I know there are new headers etc in firefox and IE but I would recommend staying away from it all together
  • epoy
  • Newbie
  • Newbie
  • epoy
  • Posts: 13
  • Loc: Phillipines

Post 3+ Months Ago

actually I discribed it as
Code: [ Select ]
js·mydomain·com to mydomain·com.


I want to put the Javascript files in js·domain·com as static files and generate viewable pages using a MVC framework in mydomain·com, I have red that subdomains are also blocked by the "Same Origin Policy".

Is there a file/or xml file that I can setup to allow my main domain to use my js files on my subdomain.

tnx ^_^
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13503
  • Loc: Florida

Post 3+ Months Ago

If you're referring to things like XML/AJAX and the HTMLCanvas element not wanting to give up pixel data, no. There's currently no way around it. If you find one, it's a bug and will be "fixed" right about the time people start using your application regularly. Never fails.

I'm guessing you're used to Flash and cross domain policy files, there's nothing like that for Javascript. When Firefox came around not too many years ago with their "most secure browser" gimmick, the major browser makers followed suit and it's getting tougher and tougher to share resources across domains.
  • epoy
  • Newbie
  • Newbie
  • epoy
  • Posts: 13
  • Loc: Phillipines

Post 3+ Months Ago

Therefore I can't do anything about that? I'll just stick on having the js files on the same URL.

I have this follow-up question. How can Google share js files on adsense?

Tnx guys
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13503
  • Loc: Florida

Post 3+ Months Ago

It's not the JS itself that's subject to cross domain issues, it's other resources such as XMLHTTPRequest objects, frames, and HTMLCanvas elements.

The reason JS files work for Adsense, Facebook's API, etc, is because they don't use any of these objects.
  • R.L.D.
  • Student
  • Student
  • User avatar
  • Posts: 83
  • Loc: Astoria,Queens

Post 3+ Months Ago

What i do is, i create an Apache Alias for the entire server that points to a folder where i keep a bunch of assets to be used from all domains and subdomains on the server.

Assuming you can SSH into your server, you could create a folder like

Code: [ Select ]
/var/www/vhosts/assets/js


put all your JS stuff in there and create an Alias

Code: [ Select ]
Alias /assets "/var/www/vhosts/assets"

<Directory "/var/www/vhosts/assets">
  Options FollowSymlinks
  AllowOverride None 
  Order allow,deny
  Allow from all
</Directory>
  1. Alias /assets "/var/www/vhosts/assets"
  2. <Directory "/var/www/vhosts/assets">
  3.   Options FollowSymlinks
  4.   AllowOverride None 
  5.   Order allow,deny
  6.   Allow from all
  7. </Directory>


put that in your apache's config file or any other file and have apache load it.

Now you can access your scripts from any site on your server by going to..

/assets/js/file.js

Can be useful for hosting libraries and such, you only have to update one file when new releases come out and all sites that use will have the latest build ready to go.

Of course you can also create a subdomain just for scripts, but i find this method more flexible.
  • epoy
  • Newbie
  • Newbie
  • epoy
  • Posts: 13
  • Loc: Phillipines

Post 3+ Months Ago

tnx for the help guys.

Post Information

  • Total Posts in this topic: 10 posts
  • Users browsing this forum: No registered users and 96 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.