• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jQuery in Action: How do I externalize javascript

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am wondering if jQuery in Action addresses: How to externalize javascript
from the JSP (or whatever) that generates the webpage.

I have created a .JSP that has a good deal of javascript in it.
But, trying to pull it out seems to be a major pain.
The biggest problem seems to be scriptlet tags.

The reason I want to pull it out is because
it increases the size of the webpage and thus the load time is longer.

Or, perhaps, jQuery in Action addresses
a good design where the javascript is created separate from webpage?

Waiting for a detailed reply,
Mike
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suspect you're doing things like...



And the problem with externalizing the JS is you need access to those variables. Hidden fields are a good way of dealing with this. Also the metadata plugin for jQuery really helps. If you were to post a section of the code that is causing you issues with externalization we might be able to give you some tips on how to deal with it.

I'll let Bear address this with regards to his book.
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The book does not address server-side issues.

But Gregg hit upon the key -- data (especially server-side data injected into the page via JSP -- EL, please avoid scriptlets) should be segregated from the code (rather than hard-coding) by tacking it onto the various elements.

The book examples do show this in action.

The meta-data capability is one way to do this, but I'm fond of using HTML5-style custom attributes (which can be used in HTML4 if you don't care about validators complaining) as they do not require extra code or plugins.
 
Mike Farnham
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We typically assign the request attribute to a variable
then reference the variable.

In the case where it is just a constant, that could be a hard-coded value.

Here is part of an example where we are using JSTL.


We are building an array of keys so we can build
a page that allows the customer to walk through the array.



 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic