HTC Components with > 512 bytes of javascript slow to unload

D

davedave

When using large number of copies of a lightweight HTC behavior
component that contains more than 512 bytes of javascript code, the
page takes a LONG time to unload the page (such as by closing the
window, refreshing the page, navigating elsewhere, etc). In the
example below, running on my machine, it takes about 0.02 seconds /
component to unload the page, making the component pretty unusable.
If I shrink the javascript code below the 512 byte limit, it will
unload instantly.

The 512 byte limit only affects the contents of the <script
language=javascript></script> section of the behavior. You can have
as many <public:property>, <public:method>, or <public:attach> tags as
you want without affecting unload speed.

This is only a problem when using Javascript or JScript as the
scripting language. Rewritting the component to use VBScript fixes
the problem.

Also, for some silly reason, including a blank <script
language=VBScript></script> before the <script language=javascript>
tag inside the component also fixes the problem.

My environment: IE6 on Win2k with all patches.

The following will unload slowly. Taking out the "Z" in the first
line of javascript code below will fix everything.

MyPage.asp:
-------------------------------
<html>
<head>
<style>
.MyClass {behavior:url('MyBehavior.htc');
</style>
</head>

<body>
<%
for i = 1 to 500
Response.Write "<input type=text class=MyClass><br>"
next
%>
</body>
</html>

MyBehavior.htc:
-------------------------------
<public:component lightweight=true>
<script language=javascript>
var Zaaaaaaaa, bbbbbbbbbbbb, cccccccccccccccc, ddddddddddddddddd;
function aaaaaaaaaaaaaaa() {};
function bbbbbbbbbbbb() {};
function cccccccccccccc() {};
function ddddddddddddddddddd() {};
function eeeeeeeeeeeeee() {};
function ffffffffffffffffffff() {};
function ggggggggggggggggg() {};
function hhhhhhhhhhhhhhh() {};
function iiiiiiiiiiiiii() {};
function jjjjjjjjjjjjjjjjj() {};
function kkkkkkkkkkkk() {};
function llllllllll() {};
function mmmmmmmmmmmmmmmm() {};
function zzzzzzzzzz1() {};
</script>
</public:component>


this version of MyBehavior.htc works fine:
-------------------------------
<public:component lightweight=true>
<script language=javascript>
var aaaaaaaa, bbbbbbbbbbbb, cccccccccccccccc, ddddddddddddddddd;
function aaaaaaaaaaaaaaa() {};
function bbbbbbbbbbbb() {};
function cccccccccccccc() {};
function ddddddddddddddddddd() {};
function eeeeeeeeeeeeee() {};
function ffffffffffffffffffff() {};
function ggggggggggggggggg() {};
function hhhhhhhhhhhhhhh() {};
function iiiiiiiiiiiiii() {};
function jjjjjjjjjjjjjjjjj() {};
function kkkkkkkkkkkk() {};
function llllllllll() {};
function mmmmmmmmmmmmmmmm() {};
function zzzzzzzzzz1() {};
</script>
</public:component>

and for some silly reason, this works fine:
-------------------------------
<public:component lightweight=true>
<script language=VBScript></script>
<script language=javascript>
var Zaaaaaaaa, bbbbbbbbbbbb, cccccccccccccccc, ddddddddddddddddd;
function aaaaaaaaaaaaaaa() {};
function bbbbbbbbbbbb() {};
function cccccccccccccc() {};
function ddddddddddddddddddd() {};
function eeeeeeeeeeeeee() {};
function ffffffffffffffffffff() {};
function ggggggggggggggggg() {};
function hhhhhhhhhhhhhhh() {};
function iiiiiiiiiiiiii() {};
function jjjjjjjjjjjjjjjjj() {};
function kkkkkkkkkkkk() {};
function llllllllll() {};
function mmmmmmmmmmmmmmmm() {};
function zzzzzzzzzz1() {};
</script>
</public:component>
 
D

davedave

Correction: you need to put the <script language=VBScript></script>
code AFTER your javascript code or the behavior will stop working
under some circumstances (if anyone from Microsoft is actually looking
at this, feel free to contact me for more details).

Works:
<public:component lightweight=true>
<script language=javascript>
// Your code here
</script>
<script language=VBScript></script>
</public:component>

Doesn't always work:
<public:component lightweight=true>
<script language=VBScript></script>
<script language=javascript>
// Your code here
</script>
</public:component>

--------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top