Jump to content

Question for .js guru's


PrestaHeroes USA

Recommended Posts

Curios about something I see in PrestaShop and CMS's in general.

 

when we look at a non-CCC (just for sake of clarity) the called .js files in page source we can see in many shops multiple calls to same .js files, but from different file/remote locations.

 

for example

 

somejshere/somejshere.js

/js/somejshere/somejshere.js

 

while PrestaShop will remove duplicate .js calls when location is the same, it does not however remove duplicate .js file names.

 

The question I have will browser use the 'last' called .js file functions?

 

thanks in advance for your review and thoughts

 

el (fred)

Link to comment
Share on other sites

everything depends on script. for example, if you will run some scripts that load some external libraries (for example facebook libraries with app id definition) browser will load FIRST script, second will not be loaded (in fact it will be loaded, but it will not be executed due to the fact that facebook object was created before in first library).

 

usually for standard scripts: both files will be executed in order related to position in the code (page body).

for example, your page loads two script files

 

/myscript/script1.js with code:

function something(){

alert("1");

}

 

/somedirectory/script1,js with code:

function something(){

alert("2");

}

 
 
 
if you will call someting(); you will see "2" message box, because second file overwrited something() function with own function contents.
Link to comment
Share on other sites

 

everything depends on script. for example, if you will run some scripts that load some external libraries (for example facebook libraries with app id definition) browser will load FIRST script, second will not be loaded (in fact it will be loaded, but it will not be executed due to the fact that facebook object was created before in first library).

 

usually for standard scripts: both files will be executed in order related to position in the code (page body).

for example, your page loads two script files

 

/myscript/script1.js with code:

function something(){

alert("1");

}

 

/somedirectory/script1,js with code:

function something(){

alert("2");

}

 
 
 
if you will call someting(); you will see "2" message box, because second file overwrited something() function with own function contents.

 

 

thank you, I felt this must be how it works without using something like namespace.

 

I have code (experimental and in test) that deletes any duplicate .js and keep only the last one.  When I write code I must make some assumption...that earlier duplicate file names will be replaced by subsequent calls.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...