How to load cdn jquery with local fallback in the footer and remove jQuery UI?
I'm trying to control how jQuery loads - ideally I'd like to:
- Have jQuery load from Google with a local fallback
- Move the loading of jQuery to the footer
I'd prefer to do this without a plugin and have duplicated header_required.php & footer_required.php to the root /elements directory, then edited like this:
This seems to work but when logged in, the edit bar doesn't load - if I move the jQuery loading back to header.php then the edit bar works.
Also, jQuery UI seems to load in the header but I can't find this to move or turn off - how would I figure out where that loads from and what would be the best way to control it?
So those are changes to the html helper that gets loaded into header_required.php - is that right? And so I would just override in the top-level /helpers directory?
Sorry, my php is basic!
- Copied the contents of your file to: /helpers/core/html.php
- Added the following to site.php
I guessed that ASSET_MAP_ALL_FILE_JQUERYJS is a constant which should be added to site.php but am not sure how to add the CDN with local fallback.
I'm not seeing any errors but jQuery isn't loading so assume that I'm not doing this right.
Any pointers would be much appreciated.
I'm having difficulty tracking down and controlling the css/js files that c5 and blocks load.
I realise a lot of developers don't care but it would be nice if c5 followed best practice. i.e. load 1 css file in the header and 1 js file in the footer - or at least have the flexibility to control how files combine and where they load more easily.
There doesn't seem to be much discussion and if there is, it looks complex (Miser etc)
I only have content blocks, a page_list block and a designer_content block on this page.
Is there a good way to trace dependancies back to their block?
<link href="/blocks/page_list/view.css?v=16bf1a84501e5d8f74e3e8fd817663f4" type="text/css" rel="stylesheet">
This css file has html in it (when viewed in Firebug) and loads:
I haven't seen this before - is that weird? We're using a custom template (based on Jordan's clean page_list templates) and don't have any js dependancies so assume this is loading from the core?
At this point, my overridden header_required.php file has jQuery loading on the front-end like this:
I'm a bit confused about how this all works sorry.
I had the code working on one of my c5.6 development sites (in fact, it still is when I test anything on that version of c5).
Its main purpose was as a means of blocking asset collisions within a site. CDN mapping came as a side effect.
UI may be best not to map because C5 uses a non-standard build (at least it used to, not sure if it still does).
For local fallback, you would need some (non jquery) script on the page to load jQuery after the CDN failed to load. Its not a favoured way of doing things because there will necessarily be a delay before the CDN load attempt times out and the local fallback then initiates loading (such decisions can be cached/optimised).
Anyway, the modified helper provides a means to experiment.
For more comprehensive re-mapping, combination and minification, have a look at miser (I have never used it, maybe not so much a hot topic now as it was 18 months ago).
There are several threads if you search the c5 forums.
There is also a php backtrace call, that will give levels of stack dump, so can be used in a similar way but with more verbose info.