Forums / Bug Reports / [Not a bug] /** CDN for jQuery core **/

[Not a bug] /** CDN for jQuery core **/

Views: 2,670

Results 1 to 11 of 11
16 Feb 2015, 10:20 PM
#1
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

[Not a bug] /** CDN for jQuery core **/

Wasn't sure where to post this or if it has been addressed :blush:

In v154 jQuery is being called after the load for all site-wide jscript_*.js files located within the custom templates folder.

Was this intentional?

If so, why?

This means all site-wide jscript_.js files will have to be called from page-specific jscript_.js or site-wide jscript_*.php files.

zen-cart-v1.5.4-12302014 download

16 Feb 2015, 10:46 PM
#2
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: [Not a bug] /** CDN for jQuery core **/

So this is weird:

2 - 154 download

1 - uploaded jscript_jquery-1.11.2.min.js

  • Works as I think it was intended - removes calls to CDN

2 - uploaded jquery-1.11.2.min.js

  • Called it from jscript_php file
  • Doesn't load
  • Loads jscript_file.js
  • Shows jscript_file.js above CDN calls
16 Feb 2015, 11:15 PM
#3
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: [Not a bug] /** CDN for jQuery core **/

** Disregard **

or even

** Delete Thread **

All works as intended, It was a simple case of misspelling

Nice job on this BTW! :bigups:

17 Feb 2015, 3:13 AM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: [Not a bug] /** CDN for jQuery core **/

rbarbour:

All works as intended, It was a simple case of misspelling

Nice job on this BTW! :bigups:
(whew!) At first you had me worried. Glad you got it sorted out!

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

3 Mar 2015, 8:24 AM
#5
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Re: [Not a bug] /** CDN for jQuery core **/

All right, I thought I had this, but now I have a question..

So riddle me this..

What if one has a jQuery plugin that needs to execute on every page (like say to support a navigation menu), is there another mechanism to get this jQuery plugin to be called AFTER jQuery loads, or is hard coding this into the html_header.php file after the jQuery call the best way to achieve this?? (hope this is clear as I am rather loopy tonight and probably need to go to bed soon.. :laugh:)

My Site - Zen Cart & WordPress integration specialist
I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.

3 Mar 2015, 3:27 PM
#6
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: [Not a bug] /** CDN for jQuery core **/

DivaVocals:

So riddle me this..

What if one has a jQuery plugin that needs to execute on every page (like say to support a navigation menu), is there another mechanism to get this jQuery plugin to be called AFTER jQuery loads, or is hard coding this into the html_header.php file after the jQuery call the best way to achieve this?? (hope this is clear as I am rather loopy tonight and probably need to go to bed soon.. :laugh:)

Perhaps you need to define exactly what you mean by 'JQuery plugin'.

Jquery itself is simply a code library. By itself it doesn't do anything.

If by 'JQuery plugin' you are referring to any code (or module) that makes use of the JQuery function calls, then in order for them to work the JQuery library must be loaded before the calls are made (obviously). Since there could be many modules with JQuery function calls it makes sense to load the library once upon a page load so that it is available when/where needed.

The 'plugins' themselves should be treated the same as any other Javascript code. IOW, they can be embedded where needed, or automatically loaded on a global or per page basis as required.

Perhaps I'm misunderstand the question?

Cheers
RodG

ps. Although it is possible to load two different versions of the JQuery library, this is best avoided where possible as it can cause unpredictable results. (This probably goes withoiy saying though).

NOTE: We are sorry that Rod is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

Ozpost - The Ultimate Shipping module for Australian Merchants. Click these links for its Homepage, or Download from Zen-Cart.com.

3 Mar 2015, 8:23 PM
#7
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Re: [Not a bug] /** CDN for jQuery core **/

RodG:

Perhaps you need to define exactly what you mean by 'JQuery plugin'.

Jquery itself is simply a code library. By itself it doesn't do anything.

If by 'JQuery plugin' you are referring to any code (or module) that makes use of the JQuery function calls, then in order for them to work the JQuery library must be loaded before the calls are made (obviously). Since there could be many modules with JQuery function calls it makes sense to load the library once upon a page load so that it is available when/where needed.

The 'plugins' themselves should be treated the same as any other Javascript code. IOW, they can be embedded where needed, or automatically loaded on a global or per page basis as required.

Perhaps I'm misunderstand the question?

Cheers
RodG

ps. Although it is possible to load two different versions of the JQuery library, this is best avoided where possible as it can cause unpredictable results. (This probably goes withoiy saying though).You are misunderstanding the question..

jQuery plugin = "'JQuery plugin' you are referring to any code (or module) that makes use of the JQuery function calls"

I know how jQuery plugins work.. (there are a ton of modules here which use jQuery plugins including Zen Colorbox, etc) I know that jQuery must be loaded 1st for my jQuery plugin to work.. However in the new v1.5.4 world, loading a jQuery plugin via the normal upload your jscript_[yourfilenamehere].js file to the jscript folder will mean that the plugin WILL load before jQuery does (see Raymonds initial post here).. I need this plugin to work sitewide. So a page specific javascript file will not work unless I add it to EVERY page folder..

So I want to know if hard coding the link to my jQuery plugin into the html_header.php is the ONLY way to make sure my plugin loads AFTER jQuery (AKA will load sitewide)

My Site - Zen Cart & WordPress integration specialist
I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.

3 Mar 2015, 10:09 PM
#8
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: [Not a bug] /** CDN for jQuery core **/

Crystal,

If using the built in jQuery CDN, I found it very useful to create a jscript_*****.php file, this file loads after the call to the jQuery CDN

In that file is where I call any *****.js files which load after the call to the jQuery CDN

This is also a great way to call page specific *****.js files using PHP

(EXAMPLE)

<?php if (in_array($current_page_base,explode(",",'advanced_search_result')) or $current_page_base == 'index' and $cPath != '' or $current_page_base == 'index' and  $_GET['manufacturers_id'] != '') { ?>

<script type="text/javascript" src="includes/templates/responsive_template_default/jscript/*****.js"></script>

<script type="text/javascript"><!--//

$(function() {
$(document).ready(function() {

YOUR CODE

				});
			}) (jQuery);
//--></script>
<?php } ?>

The above *****.js file and code only loads on the advanced_search_result page, all index pages where a cPath is passed or index page where a manufacturers_id is passed

or you can just call your *****.js file and code

(EXAMPLE)

<script type="text/javascript" src="includes/templates/responsive_template_default/jscript/*****.js"></script>

<script type="text/javascript"><!--//

$(function() {
$(document).ready(function() {

YOUR CODE

				});
			}) (jQuery);
//--></script>

I am still not sure why it was done this way where the built in jQuery CDN call loads after all site-wide jscript_*****.js files located within the custom templates folder but it can be used in a positive way.

You can also embed into html_header.php

just MO

DivaVocals:

You are misunderstanding the question..

jQuery plugin = "'JQuery plugin' you are referring to any code (or module) that makes use of the JQuery function calls"

I know how jQuery plugins work.. (there are a ton of modules here which use jQuery plugins including Zen Colorbox, etc) I know that jQuery must be loaded 1st for my jQuery plugin to work.. However in the new v1.5.4 world, loading a jQuery plugin via the normal upload your jscript_[yourfilenamehere].js file to the jscript folder will mean that the plugin WILL load before jQuery does (see Raymonds initial post here).. I need this plugin to work sitewide. So a page specific javascript file will not work unless I add it to EVERY page folder..

So I want to know if hard coding the link to my jQuery plugin into the html_header.php is the ONLY way to make sure my plugin loads AFTER jQuery (AKA will load sitewide)

3 Mar 2015, 10:18 PM
#9
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: [Not a bug] /** CDN for jQuery core **/

After further testing and altering, my original post turned out to be correct.

In v154 jQuery is being called **AFTER ** the load for all site-wide jscript_*.js files located within the custom templates folder.

This means all site-wide jscript_.js files will have to be called from page-specific jscript_.js

However

In v154 jQuery is being called **BEFORE ** the load for all site-wide jscript_*.php files located within the custom templates folder.

DrByte:

(whew!) At first you had me worried. Glad you got it sorted out!

3 Mar 2015, 10:22 PM
#10
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: [Not a bug] /** CDN for jQuery core **/

DivaVocals:

I know that jQuery must be loaded 1st for my jQuery plugin to work.. However in the new v1.5.4 world, loading a jQuery plugin via the normal upload your jscript_[yourfilenamehere].js file to the jscript folder will mean that the plugin WILL load before jQuery does (see Raymonds initial post here).. I need this plugin to work sitewide. So a page specific javascript file will not work unless I add it to EVERY page folder..

So I want to know if hard coding the link to my jQuery plugin into the html_header.php is the ONLY way to make sure my plugin loads AFTER jQuery (AKA will load sitewide)

While the jscript_.js files are loaded before jQuery, the jscript_.php files are not.

So, this will work:

  1. put your jQuery plugin file into the jscript folder, but do NOT add the jscript_ prefix to it.
  2. Then create a jscsript_PLUGINNAME.php file in the jscript folder, and in the .php file write only the <script> code. Not even a single line of PHP. Something like:```
<script src="includes/templates/TEMPLATENAME/jscript/THEPLUGINNAME.js"></script>

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

4 Mar 2015, 2:24 AM
#11
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Re: [Not a bug] /** CDN for jQuery core **/

rbarbour:

After further testing and altering, my original post turned out to be correct.

In v154 jQuery is being called **AFTER ** the load for all site-wide jscript_*.js files located within the custom templates folder.

This means all site-wide jscript_.js files will have to be called from page-specific jscript_.js

However

In v154 jQuery is being called **BEFORE ** the load for all site-wide jscript_*.php files located within the custom templates folder.

DrByte:

While the jscript_.js files are loaded before jQuery, the jscript_.php files are not.

So, this will work:

  1. put your jQuery plugin file into the jscript folder, but do NOT add the jscript_ prefix to it.
  2. Then create a jscsript_PLUGINNAME.php file in the jscript folder, and in the .php file write only the <script> code. Not even a single line of PHP. Something like:```
<script src="includes/templates/TEMPLATENAME/jscript/THEPLUGINNAME.js"></script>

Awesome thank you both.. My FIRST inclination was to hard code it into the html_header.php file and keep it moving:laugh:, but them I remembered this post, and thought that I should ASK before I DO.. :smile:

I do have another "how should I do this" question DrByte.. I will start a new thread for it when I'm ready.. I need to finish what I'm doing here, and then I shall poke at ya when I post it.. :smile: I am already anticipating that I will get a HUGE groan from you when I pose this question.. But rest assured it is not my intention to give you a headache at all (even if that ends up being the result..:laugh:)

My Site - Zen Cart & WordPress integration specialist
I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.