how to defer scripts called as $helper->addScript - jquery-deferred

Could someone tell me if a script called like this can be deferred:
$helper->addScript( '//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js' );
All of my scripts are called like this in my theme and i would like to defer them as per suggestions to speed up page load.
I've already tried adding defer="defer" but that did not work or i didn't use it correctly.
Thanks

Have a look:
https://docs.joomla.org/JDocument/addScript
Try this:
$helper->addScript( '//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js', 'text/javascript', true, false );

Related

HTML src onerror doesn't load fallback in time

I have the following code in my HTML file:
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"
onerror="this.onerror=null;this.src='../js/axios.min.js?v=0.26.1';"></script>
What it supposed to do, if the primary source src (the CDN) fails, it should load the fallback script onerror from my server, as a fallback solution.
But when I purposely put a typo in the first source to test it, the content part of my webpage would not load since it can't load the script (Axios), and my whole page relies on that.
However in the F12 Console I can see that the right fallback file is loaded afterwards.
So I guess what happens, is that because of the primary source src can't be loaded, it loads the fallback source onerror, but it takes a little time to "switch", and meanwhile the loading of the other parts of the HTML is ongoing. So it doesn't wait until the fallback source file is loaded.
If that's right, my question is:
How can I make the site loading wait until the fallback source is loaded in case of error with the primary source?
Because without this script my site won't work at all, so useless to go on loading without it.
Thank you.
UPDATE #1:
Maybe if I add both (CDN and own server) variants at the same time?
<script
src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"</script>
<script src="../js/axios.min.js?v=0.26.1"></script>
FYI: I must have the CDN variant there, I can't remove it. But I need a fallback solution if that fails to load. So maybe this is an acceptable solution.
What do you think? Any drawbacks?
Thank you.
I found a working solution:
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script>
if (typeof axios == 'undefined') {
document.write(unescape("%3Cscript src='../js/axios.min.js?v=0.26.1' type='text/javascript'%3E%3C/script%3E"));
}
</script>
Maybe it will be useful for somebody as well.
Thank you.

Can you restrict meta reload?

so I'm trying to use meta reload to update my website (using the code below) and I was wondering if it was possible to make it reload once after opening the page.
<meta http-equiv="refresh" content="3" >
Why, because looking at a website that refreshes every 3 seconds is really annoying to look at. If you can help, thank you.
#David's comment (original post)
To store values without files and within the webpage. I suggest you encrypt the data because it is visible in the developers console 'local storage'
function holdArray(array){
localStorage.setItem("holdArray", array);
return true;
}
function releaseArray(){
if(localStorage.hasOwnProperty('holdArray')){
return localStorage.getItem("holdArray");
}
}
Set data
holdArray(JSON.stringify(yourvariable));
Get data
let storage = releaseArray();
All I had to do to make it update once when the page was loaded was change index.html to index.php
Thank you with all the help you guys gave me, but this is all I ended up needing to do. I still very much appreciate the effort though.

Load div when i open the page

Good Morning comunity, im really new on this coding so iam sorry if this question is too noob.
I want a DIV PA load automatically a php file when i open the web page, please i dont want to load with any interval, just load instant when open web.
I tried this code but im sure it is not working
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.min.js">
</script>
<script type="text/javascript">
$(document).ready(function)()
{
$('#apDiv3').load('xFile.php');
}
);
</script>
Thank you in advance for your time!!
Have you checked the result with a debugger like Firefox's Firebug? Check the network communication to see if the ajax request was completed successfully.
Also, you can try to a callback function to see if the code was executed successfully:
$( "#result" ).load( "ajax/test.html", function() {
alert( "Load was performed." );
});
if you don't get the expected output, it might be a problem on the server-side.
Also... are you sure you are using this exact code? I don't think you should close the brackets after function
$(document).ready(function)
this is how you do it:
$(document).ready(function() {
....

Could someone explain how to install SoundManager2

I've never been able to figure this out!
Yeah I copy the java script in but what is the html code required and css??
Their website doesn't explain any of that (unless I am missing it!!)
If someone could please break it down for me I would be very grateful
Actually used this in a site before, this is what I have in my code:
In the header, assuming you have it installed in the /soundmanager2/ directory:
<script type="text/javascript" src="soundmanager2/soundmanager2.js"></script>
<script type="text/javascript">
soundManager.url = 'soundmanager2/';
soundManager.useHTML5Audio = false;
soundManager.useFlashBlock = false;
soundManager.debugMode = false;
</script>
Then on each element you want to play a sound with on click, include this attribute:
onClick="soundManager.play('Name','path/to/filename.mp3')"
Or you can simply call soundManager.play wherever you want.
Granted it is not the easiest interface in the world in terms of copy and paste code and your good to go.
However all of the demos on there site have all the CSS / HTML you need to get started writting your own themes and templates.
There site is mor about the JS behind the scenes then the look of the interface.
http://www.schillmania.com/projects/soundmanager2/demo/play-mp3-links/ (as an example)
Although I am sure you were hoping for downloadable code I hope this at least gets you pointed in the right direction.

Refresh another IFRAME Window

I have this line that works when I click the word Test:
Test
How can I re-code this so I do not have to click the word Test or select anything, just have it execute?
This should be simple, just starring at it to long.......
Update: This sort of works. It will open SearchThis.php but not in the target window, only the window it was executed from. This is inside php and the last line. I am close to a solution.....
header("Location:\\SerchThis.php target=SearchThisFrame");
Thanks to Gerben we have a solution. I cant tell you how many post and how many searches I did for this solution, nothing worked except this one. I have added code to include passing a php generated variable. I placed this script at the very end, past the last ?> and before the /body tag in order to pick up the varable.
<script>
window.open('SearchThis.php?passthis=<?php echo "Variable"; ?>', 'SearchThisFrame');
</script>
<script>
window.open('SearchThis.php', 'SearchThisFrame');
</script>