This week's book giveaway is in the Java in General forum.
We're giving away four copies of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 and have ishori Sharan & Adam L Davis on-line!
See this thread for details.
Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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: 67620
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.



 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic