Javascript Functions Running Twice | Community
Skip to main content
Aug 25, 2017 2:12 PM UTC
Solved

Javascript Functions Running Twice

Hi all -

I'm fairly new to AEM, and have run into an interesting issue. The component I'm building is going to be a financial application that our users fill out. (Think along the lines of filling out an application at a bank to open up a new account.)

I've got a couple of Javascript files in the component, and everything was working great yesterday. Then, at some point, all of my JS functions started running twice. I have one function that logs a "Hello World" to the console when the page is loaded, and it logs that value twice. Same for my jQuery functions - anything that fires on a click runs twice.

I'm not sure what happened to cause this. Like I said, it worked correctly for a while. Any ideas on what might be causing this?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
smacdonald2008
smacdonald2008Accepted solution
Level 10
Aug 28, 2017 8:00 PM UTC

Can you try packaging up the app and all the dependencies and try to deploy to a clean install of AEM. Lets rule out an issue with the AEM instance first.

15 replies

Aug 25, 2017 4:15 PM UTC

Should I take one of those mentions out? I'm not sure if that's the right way to fix the issue.

Translate
Aug 25, 2017 3:43 PM UTC

Ok, I have that line in both my headlibs.html and footlibs.html files in my partials folder. Both files say that headlibs will only load the CSS, and that the footlibs will load the Javascript.

Translate
smacdonald2008
Level 10
Aug 25, 2017 3:13 PM UTC

IN which file are you specifying the reference to the clientlib. Make sure that you only have this line once:

<sly data-sly-use.clientLib="/libs/granite/sightly/templates/clientlib.html" data-sly-call="${clientLib.js @ categories='<NAME OF CLIENT LIB>}"

Translate
Aug 25, 2017 3:07 PM UTC

Yes, I'm using ClientLibs to store my JS. Here's a shot of my project below. I'm not sure if/how they could be getting loaded twice. Where would I look to see if that's the case?

Translate
smacdonald2008
Level 10
Aug 25, 2017 2:52 PM UTC

Are you using ClientLibs to store the JS logic? If so - would they be loading twice somewhere?

Translate