Skip to main content
Jai1122
Level 4
Oct 16, 2015 2:28 AM UTC
Solved

Client libs error

Hi All,

     My html structure is as follows,

<html> <head> <cq:includeClientLib css="my.categories" /> </head> <body> <!--Header Files--> <!--Navigation files--> <!--Main Body Starts here--> <!--Component that uses jQuery--> $(document).load(function(){ //do something }); <!--Footer part starts here --> <footer> <cq:includeClientLib js="cq.jquery" /> <cq:includeClientLib js="my.categories" /> </footer> </body> </html>

Since i am loading the jQuery clientlib at the footer the jquery in the component is not working. It says $ is not defined. 

In such case is it impossible to use jQuery? Kindly let me know how i can proceed!!! 

Thanks,

Jai.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
ogillAccepted solution
Adobe Employee
Oct 16, 2015 2:28 AM UTC

Get you now, as you probably know putting the call to load the client libraries at the bottom is done to improve page load times [1][2]. 

I'd explain your issue to the tech lead or try what Praveen suggested.

Regards,

Opkar

[1] https://developer.yahoo.com/performance/rules.html#js_bottom

[2] http://stackoverflow.com/questions/9814301/is-it-practically-good-to-put-js-files-at-the-bottom-of-webpage

8 replies

Jai1122
Jai1122Author
Level 4
Oct 16, 2015 2:28 AM UTC

Thanks for that Opkar, Am waiting for your response

Translate
Adobe Employee
Oct 16, 2015 2:28 AM UTC

Here is an article you may fine useful [1]

[1] http://technologyplatforms.razorfish.com/blog/avoid-paying-jquery-tax-adobe-cq

Translate
ogillAdobe EmployeeAccepted solution
Adobe Employee
Oct 16, 2015 2:28 AM UTC

Get you now, as you probably know putting the call to load the client libraries at the bottom is done to improve page load times [1][2]. 

I'd explain your issue to the tech lead or try what Praveen suggested.

Regards,

Opkar

[1] https://developer.yahoo.com/performance/rules.html#js_bottom

[2] http://stackoverflow.com/questions/9814301/is-it-practically-good-to-put-js-files-at-the-bottom-of-webpage

Translate
Jai1122
Jai1122Author
Level 4
Oct 16, 2015 2:28 AM UTC

    Yes Opkar, if i add jquery as a dependency to my clientlib and i load my clientlib first in my component then for sure the component works.

But i do not know why they are loading jquery in the footer. This is the process they follow in this project and i am new to this project

Translate
Adobe Employee
Oct 16, 2015 2:28 AM UTC

Hi,

in the first article referenced by the link you posted [1], they add jquery as a dependency to their custom client library. This is preferable to making a separate call to load jquery. Any reason you were loading JQuery in the footer?

Regards, 

Opkar

[1] http://blogs.adobe.com/mtg/2011/11/building-components-in-adobe-cq-5-part-1-a-tutorial-on-clientlibs-using-jquery-ui.html#comments

Translate
Jai1122
Jai1122Author
Level 4
Oct 16, 2015 2:28 AM UTC

Hi Edubey,

   I am making an ajax call to a servlet and processing the JSON response to populate a div in the component.

I referred some article that is similar to the one described here

Translate
edubey
Level 10
Oct 16, 2015 2:28 AM UTC
I would recommend to add a div in your component with a "id" attribute. Using this id your can manipulate/populate anything inside this div using js and place your ajax call code js file after jQuery is loaded.
Translate
edubey
Level 10
Oct 16, 2015 2:28 AM UTC
Using js/jquery code inside jsp is not a recommended practice. I would you to call same jQuery code after jQuery file is loaded. You can put that in a js file and call that file after jQuery is loaded. Can you tell what u r trying to do by using this jQuery in jsp file?       
Translate