jQuery loading in local dev but not in live site
Permalink
Hi, all. I have a homepage slider that works perfectly in my local dev site both logged in and logged out. I'm now building out my live site (www.brandsistency.com) but the slider only works when I'm logged in.
Looking at the page source, jQuery is only loading when I'm logged in. I see this injected at line 27...
... but it's not there in the logged out source. In the dev site, I see the equivalent script appear both logged in and logged out.
I've copied over all the same code from dev to live, so why the different behaviour? Why isn't jQuery loading in my logged out live site?
FYI, dev is running 5.7.5.2 and live is on 5.7.5.7.
Thanks in advance for any help!
Looking at the page source, jQuery is only loading when I'm logged in. I see this injected at line 27...
<script type="text/javascript" src="/concrete/js/jquery.js"></script>
I've copied over all the same code from dev to live, so why the different behaviour? Why isn't jQuery loading in my logged out live site?
FYI, dev is running 5.7.5.2 and live is on 5.7.5.7.
Thanks in advance for any help!
How are you requiring jQuery in your code?
Hi, John. Sorry but I'm not quite with you – bit of a novice with jQuery and javascript. I'll try to explain.
I have a PHP block on the homepage with contains the content for the three frames of the slider (based on Unslider) plus the javascript controls, which require jQuery. I'm relying on the jQuery inserted by c5.
In my header.php files I have the code
and of course it's at the end of that section that the jQuery line gets added. For some reason, which I can't fathom, the jQuery line is being omitted only in the live site when logged out.
I have a PHP block on the homepage with contains the content for the three frames of the slider (based on Unslider) plus the javascript controls, which require jQuery. I'm relying on the jQuery inserted by c5.
In my header.php files I have the code
<?php Loader::element('header_required'); ?>
That would be the root of your problem. The php block is executing php. It is not loading assets used by any embedded JavaScript (ie jQuery) within the php.
There is a very good reason why the various php blocks in the marketplace are classified black/bleeding edge. A php block is at best a vulgar hack that could be of use to an experienced c5 developer for a temporary experiment. If you need to integrate a new slider, you should be developing a complete block, either from scratch or using an addon like block designer to create a starting point. The block controller within that block should then require jQuery as an asset or load it as a header item.
There is a very good reason why the various php blocks in the marketplace are classified black/bleeding edge. A php block is at best a vulgar hack that could be of use to an experienced c5 developer for a temporary experiment. If you need to integrate a new slider, you should be developing a complete block, either from scratch or using an addon like block designer to create a starting point. The block controller within that block should then require jQuery as an asset or load it as a header item.
Hi, John.
I got to the bottom of my problem. It turned out the page_theme.php file hadn't copied across properly. Once I spotted that, I uninstalled and reinstalled my custom theme and, hey presto, the slider works!
FYI, I'm using lobar's 'Php Code Block' because I needed to include
together with my HTML and javascript to overcome the logged in/out issue previously. I appreciate it might not be the ideal solution but it works for me for now.
Anyway, problem solved. Many thanks for your help and apologies if I wasted your time!
I got to the bottom of my problem. It turned out the page_theme.php file hadn't copied across properly. Once I spotted that, I uninstalled and reinstalled my custom theme and, hey presto, the slider works!
FYI, I'm using lobar's 'Php Code Block' because I needed to include
<?php if(!$page->isEditMode()): ?>
Anyway, problem solved. Many thanks for your help and apologies if I wasted your time!
First:
** Clear cache and set "cache-and-speed-settings" to correct preference for dev.
** Local vs remote is nothing do to with this problem (Only by Coincidence you think that this is relate) - cache mabye.
Now, Your site and the C5 admin "live together" :) when you are login (In any CMS) - Concrete5 use CSS and JS assets for dropdown, menus and so on.
Example: I create empty theme - only print "hello world" (deafult.php with one line in my body - no css or extra JS). Now login => view the source ==> see a lot of C5 assets (css/JS) - Jquery is one of them.
This "line 27":
Go to root folder => concrete => JS : you will see this minify version of jquery
The best way to learn this issue is by viewing the source code (login - logout and Ctr+f "js" or "css" and see in "live" the assets).
When you "logout" you dont load this assets. So you must
(1)Provide this assets (load in your head.php , fotter.php js and css "<link href="...bla bla bla" or <script src="bla bla...) - tell C5 dont use "line 27" use my own vesrsion of jquery (rare).
(2) Require this assets from C5 system - use "line 27" also when i logout
(and!! delete the call to this assets in you head.php or fotter.php - "dont load twice") (popular).
see her (for dev):
http://documentation.concrete5.org/developers/designing-for-concret...
Most of the times you load big library like Jquery from theme level (You want this library for all of your JS components - bootstrap, foundation etc). So you dont need to call this library from block level (view.js or by controller functions).
** Clear cache and set "cache-and-speed-settings" to correct preference for dev.
** Local vs remote is nothing do to with this problem (Only by Coincidence you think that this is relate) - cache mabye.
Now, Your site and the C5 admin "live together" :) when you are login (In any CMS) - Concrete5 use CSS and JS assets for dropdown, menus and so on.
Example: I create empty theme - only print "hello world" (deafult.php with one line in my body - no css or extra JS). Now login => view the source ==> see a lot of C5 assets (css/JS) - Jquery is one of them.
This "line 27":
<script type="text/javascript" src="/concrete/js/jquery.js"></script>
Go to root folder => concrete => JS : you will see this minify version of jquery
The best way to learn this issue is by viewing the source code (login - logout and Ctr+f "js" or "css" and see in "live" the assets).
When you "logout" you dont load this assets. So you must
(1)Provide this assets (load in your head.php , fotter.php js and css "<link href="...bla bla bla" or <script src="bla bla...) - tell C5 dont use "line 27" use my own vesrsion of jquery (rare).
(2) Require this assets from C5 system - use "line 27" also when i logout
(and!! delete the call to this assets in you head.php or fotter.php - "dont load twice") (popular).
see her (for dev):
http://documentation.concrete5.org/developers/designing-for-concret...
Most of the times you load big library like Jquery from theme level (You want this library for all of your JS components - bootstrap, foundation etc). So you dont need to call this library from block level (view.js or by controller functions).
And in your specific link its easy to know the problem (inspect element in chrome):
You get red errors:
* Uncaught ReferenceError: jQuery is not defined
So call to jQuery (<src=....) in some way (provide - or req)
You get red errors:
* Uncaught ReferenceError: jQuery is not defined
So call to jQuery (<src=....) in some way (provide - or req)
Thanks for your reply, Ezra.
I had done most, if not all, of your suggestions and I wasn't getting anywhere. And I know the local vs remote question wasn't the root of the problem. I just couldn't work out why the two sites were behaving differently when I thought they were set-up the same.
It turns out they weren't the same because my page_theme.php file hadn't copied across during the FTP transfer and I hadn't spotted it. Doh! I sorted that out and everything's working fine now.
I had done most, if not all, of your suggestions and I wasn't getting anywhere. And I know the local vs remote question wasn't the root of the problem. I just couldn't work out why the two sites were behaving differently when I thought they were set-up the same.
It turns out they weren't the same because my page_theme.php file hadn't copied across during the FTP transfer and I hadn't spotted it. Doh! I sorted that out and everything's working fine now.
I am glad. Anyway this is good post for future searches (Most of the time in code the problem was "stupid" or "tiny" so its ok).