Tasty vector graphics carry unnecessary <script> tag with JS body inside innerHTML
Created by: reiniervandijk
Gendl server responds with unnecessarily large data on viewport geometry changes while viewing vector graphics. This is due to the fact that JS data is carried both inside the innerHTML part of the response AND in the jsToEval part. The latter is clear, while the former seems unnecessary. Refresh events in the browser will not cast problems.
Solution: in base-ajax-graphics-sheet.lisp, comment out:
(define-lens (html-format base-ajax-graphics-sheet)()
:output-functions
(....
(vector-graphics
.....
;;; (let ((raphael-string (the raphael-string)))
;;; (htm ((:script :type "text/javascript")
;;; (str raphael-string))))
...
))
Imported comments:
By genworks on 2013-07-09 22:26:05 UTC
Commenting out the script in the section's innerHTML is not a solution, because the JS still has to be there as part of the normal page (i.e. we still want the JS to get evaluated on a normal browser refresh or similarly if this page is being loaded originally and not through gdlAjax).
The solution in cases like this where there is a redundancy between the js-to-eval and the contents of script tags in the innerhtml is to parse and evaluate the javascript code directly from within the innerHTML as part of the Ajax update function. It looks like this:
var codes = elem.getElementsByTagName("script");
for(var i=0;i<codes.length;i++)
{
eval(codes[i].text);
}
This also simplifies server-side logic and removes knotty dependency issues.
On the application side, for sheet-sections where the js-to-eval is known to be redundant with what is included in one or more script tags in the inner-html, the protocol will be to specify:
(js-to-eval :parse)
instead of giving actual javascript content. The keyword :parse is recognized and the respond-with-new-html-sections (server-side) and gdlUpdate (client-side) will behave accordingly.
This has been implemented in a local feature branch which will be pushed to master for upcoming release. (all of respond-with-new-html-sections has been cleaned up and rewritten in proper GDL style for better robustness and ease of maintenance).