Project

General

Profile

Actions

Bug #872

closed

Javascript files shuffeled on browser refresh

Added by Anonymous almost 13 years ago. Updated over 12 years ago.

Status:
Closed
Priority:
Urgent
Assignee:
Pieter Libin
Category:
-
Target version:
-
Start date:
06/24/2011
Due date:
% Done:

0%

Estimated time:

Description

Hello,

When refreshing the browser, the page is rerendered BUT the javascript files are shuffled in the page header.

Exemple:

Before refresh:

<head>
<title></title>
 ...
<script type="text/javascript">...</script>
<script src="site?wtd=2ba1c7ef6b00e0f8c71db77c6751&amp;request=script&amp;rand=-594049106"></script>
<style type="text/css" id="Wt-inline-css"></style>
<script src="ressources/jquerytools/jquery.tools.min.js"></script>
</head>

After refresh:

...

The refreshed page does not work properly because jquery tools need jQuery. After the refresh, jQuery is load last (in the JWt library). This result in an error: "JQuery is not defined" and a jwt JavaScript internal error when trying to use jquery tools in the same event handling loop as the refresh.

FYI: the jwt error totally cripples the application.

Kind regards,

Thim.

Thim.


Files

WebRenderer.java (39.3 KB) WebRenderer.java Thim Anneessens, 06/25/2011 10:45 AM
Hybrid.html (1.2 KB) Hybrid.html Thim Anneessens, 06/25/2011 10:45 AM

Updated by Thim Anneessens almost 13 years ago

Because I am such a nice guy, here is the bug fix:

As I understand it, the problem was that when serving a page without bootstrap, the js libraries are appended to the style sheets. And both where added AFTER the output js code (like

).

I therefore modified the following files.

2 Files to modify, bug fix only (no added features):

- Hybrid.html => Add a new variable to the template. $_SCRIPTS_$. The variable is put AFTER the $_BOOT_JS_$ block so that we have consistent and compatible behaviors.

  • WebRenderer.java => No use adding a variable if we do not use it. Modifications are marked by "MODIF". They are all the WebRenderer#serveMainpage() method.

Ok that's it. I don't know much about JWt internal working, so feel free to correct me when I am wrong.

Best regards,

Thim.

Actions #2

Updated by Koen Deforche almost 13 years ago

  • Status changed from New to Feedback

Hey Thim,

There is however some sense to this: the loading of Wt's script library is deferred until after the page is rendered, since in Hybrid bootstrap, it is not strictly required and thus it would increase the perceived load time.

I believe what we should do is document that you should load JQuery yourself if you are going to rely on it.

In that way you can also load the version of JQuery you need instead of the (rather old but sufficiently capable for the needs of Wt) version of JQuery that is distributed with Wt. The version that comes with Wt will then not be loaded and thus there is no overhead.

Would that be an acceptible solution for you?

Regards,

koen

Actions #3

Updated by Thim Anneessens almost 13 years ago

Hi Koen,

Thanks for the quit reply and sorry for my tardiness ;).

Overhead:

I do not see how it creates an overhead. If I understand the code right, serveMainPage() is only called on page refresh (not on application bootstrap). I load the js in the Hybrid template only in serveMainPage().

Overhead could only occur on page refresh. One possible solution to this overhead could be to only do as I proposed if there are user defined JQuery libraries.

Proposed solution with JWt 3.1.8(see post above)

It does not work because on refresh:

  1. My Jquery library gets compiled
  2. My Jquery Tools lib gets compiled and linked with the compiled JQuery library
  3. JWt standard JQuery lib gets compiled => Redefining (not overloading) methods and breaking links made between the previously load libraries.
    => JQuery Tools is useless.

Proposed solution with JWt 3.1.9 (see post above)

I have never used JWt 3.1.9 so I did not try. But I see 1 potential problem with the solution:

I do not see how we could JWt could determine in a consistent way that the user has loaded its own Jquery library. If it cannot do that, it cannot prevent the loading of the provided Jquery 1.4.

If it does not prevent it, we will have the same problem as explained above.

JWt is great and one of the greatest things about it that it is so easy and straight forward. So the proposed solution seems acceptable. But as I understand it I don't think it would work for the reason explained about. But maybe I am missing something.

Best regards,

Thim.

Actions #4

Updated by Pieter Libin over 12 years ago

  • Status changed from Feedback to InProgress
  • Assignee set to Pieter Libin
Actions #5

Updated by Pieter Libin over 12 years ago

  • Status changed from InProgress to Resolved

JWt only determines whether JQuery was loaded or not, not which version was loaded.

If you use WApplication#require() to load your preferred version of the JQuery library, this version will always be the one that is used.

When progressive bootstrap is used, the version specified by you will be the one that is initially loaded, JWt will notice a JQuery library was loaded and will no longer load the JQuery library shipped with JWt.

When no progressive bootstrap is used, JWt will automatically load the version of JQuery shipped with JWt when starting, afterwards the Javascript generated by your WApplication#require() invocation will load the version of JQuery you've specified.

Actions #6

Updated by Koen Deforche over 12 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF