Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update/add #3

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Update/add #3

wants to merge 5 commits into from

Conversation

WarManiac
Copy link

Update/add:
add localStorage check -> _loadScript(...) change for support no local localStorage
add support for css file
add all callback's are worked on when (xmlhttp.status != 200) in _cacheScript()

Update:
add localStorage check -> _loadScript(...) change for support no local localStorage
add support css file
Update:
add localStorage check -> _loadScript(...) change for support no local localStorage
add support css file
add all callback's are worked on when (xmlhttp.status != 200) in _cacheScript()
@Jolly-Pirate
Copy link

Very neet to add css support, but this pull request breaks the callback:

      requireScript('jquery', '3.5.1', 'https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js', false, function () {
        requireScript('bootstrap', '4.5.3', 'js/bootstrap.bundle.min.js');
      });

Gives an error ReferenceError: $ is not defined[Learn More]. I have to refresh the page for it to work.

However it works ok without a callback

requireScript('jquery', '3.5.1', 'https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js')
requireScript('bootstrap', '4.5.3', 'js/bootstrap.bundle.min.js');

@WarManiac
Copy link
Author

requireScript('jquery', '3.5.1', 'https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js', false, function () { requireScript('bootstrap', '4.5.3', 'js/bootstrap.bundle.min.js', false); });
pls test this!
$Boolean = false = js
$Boolean = frue = css
requireScript($Name, $Version, $Url, $Boolean, function () {
requireScript($Name, $Version, $Url, $Boolean);
});

@Jolly-Pirate
Copy link

Jolly-Pirate commented Oct 26, 2020

Using your latest code, adding the boolean didn't matter (it's good to add it anyways). If I put the callback block at the top of all the other scripts (which are not loaded by requireScript), then it works right away. But if the block is after those scripts, then the problem arises and requires a refresh. Weird.

Also, keep in mind to do a localStorage.clear() when you're testing.

@WarManiac
Copy link
Author

WarManiac commented Oct 26, 2020

not localStorage.clear()
over F12, manuel clear localStorage (IE, Chrome, FF) and load page new

when load the page:
this is my code an not in console ReferenceError: $ is not defined[Learn More] and not a alert.

when press "Home" or "Options" on link alert

<script type="text/javascript">
            requireScript('BO', '0.0.1', 'themes/BO.min.css',true,
                function(){requireScript('jquery.mobile.icons.min.css', '0.0.1', 'themes/jquery.mobile.icons.min.css', true,
                    function(){requireScript('jquery.mobile.structure', '1.4.5', 'jquery.mobile.structure-1.4.5.min.css', true,
                        function(){requireScript('jquery', '1.11.1', 'jquery-1.11.1.min.js',false,
                            function(){requireScript('jquery.mobile', '1.4.5', 'jquery.mobile-1.4.5.min.js', false)
                                      })
                                  })
                              })
                          }
                         )
            window.onload = function() {
                if (!window.jQuery) {  
                    alert('jQuery');
                } else {
                    $('a').click(function() {
                        alert( "Handler for .click() called." );
                    });                    
                }
                
            }
</script>

html

	<body>
	<div data-role="header" style="overflow:hidden;">
	<h1>TEST</h1>
        <a href="#" data-icon="bullets" class="ui-btn-left">Home</a>
		<a href="#" data-icon="gear" class="ui-btn-right">Options</a>
	</div><!-- /header -->
	</body>

@WarManiac
Copy link
Author

WarManiac commented Oct 26, 2020

my Load Order :

<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>test</title>
<script type="text/javascript">
 cached-webpgr
 requireScript CSS, CSS, ..., JS, JS, ...
 window.onload = function() {
   $().xyz(function(){ code });
   function abc() { code }
 }
</script>
</head>
<body> html code. i use not script in body or end! Is in localStorage!
</body>
</html>

@select
Copy link
Owner

select commented Nov 10, 2020

Hey guys, I really appreciate your effort. As you can see, I have not worked on this project for a loooooong time. But the moment is good so I will have a look in the next weeks and join the discussion. Sory the time frame is not a bit more tight, but the situation dictates it.

Copy link
Owner

@select select left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks this is just the first thing I saw, I will have a further look soon.

* @param {string} url (see `requireScript` or 'css')
* @param {string} name (see `requireScript` or 'css')
* @param {string} version (see `requireScript` or 'css')
* @param {Boolean} css (false =js, true=css)
Copy link
Owner

@select select Nov 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a string would be better here so the API is clearer so I would change this to type: ['css' || 'js], or we parse the url suffix, which should be even better since the API would not change.

var extension = url.split('.').pop()
if (extension === 'js') ...
if (extension === 'css') ...

or you could even do

var css = url.split('.').pop() === 'css'

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • German
    habe mal "cached-webpgr" zerlegt und zu einer version 2 überarbeitet!
    js und css werden unterstütz!
    vielleicht ist die Ideen/Überarbeitung Ansatz interessant für dich.
  • English translation by google
    I disassembled "cached webpgr" and belonged to version 2!
    js and css are processed!
    Perhaps the ideas / revision approach is interesting for you.

cached-webpgr-alpha-v2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants