태터데스크 관리자

도움말
닫기
적용하기   첫페이지 만들기

태터데스크 메시지

저장하였습니다.

'2008/05/15'에 해당되는 글 6건

  1. 2008/05/15 하루 한번... 꼭 스타벅스에~!! by cate shin (6)
  2. 2008/05/15 요즘 내가 즐겨 하고 있는거.... by cate shin (2)
  3. 2008/05/15 초대장 쏘겠습니다.(12장이요) by cate shin (8)
  4. 2008/05/15 On-Demand Javascript by cate shin
  5. 2008/05/15 XmlHttpReques 2 by cate shin
  6. 2008/05/15 XmlHttpReques 1 by cate shin
사용자 삽입 이미지
아침 또는 저녁에 하루 한번씩은 꼭 들리게 되는 스타벅스~~!!

내가 사는 오피스 아래있어서 그런지.. 들락날락.. ㅡㅡ;;;

그덕에 영수증만 겁나 늘어간다는 ㅠ0ㅠ 

회사 저녁식대가 여기로 다 빠진다 ㅋㅋ


사용자 삽입 이미지
위 사진들은 그냥 명목에 불가하다...내가 바라는건 딴곳에 있었거늘..

이거 뭐 촛점도 안맞고... 될데로 찍은사진 ㅋㅋㅋ 훗~

사용자 삽입 이미지

훗... 내가....이런 잡다한걸 찍은 이윤....

그 이윤.......



그간 베일이 감춰졌던 그분을 찍기 위한..삽질이였음을...
!!


사용자 삽입 이미지


혼자서 몰래 도촬했었따..

이분 기분나쁘시다면..아놔.. ㅠ0ㅠ 

근데 더 속상한건 몰래 찍느라.. 이상하게 나왔다는거..!!

다음에 꼭 정식으로 이야기 해야지~ 사진 한장만 찍자고^0^

과연 찍어줄까??

그간 내가 스타벅스에 바른 저녁식대 및... 등등.. 한 70만원은 넘을텐데~~ 훗~~!!

암튼... 멋있던 그분..!!


다음에 더 멋있게 찍어드릴게요..도촬해서 미안 ㅠ0ㅠ
크리에이티브 커먼즈 라이선스
Creative Commons License
이올린에 북마크하기(0) 이올린에 추천하기(0)
Posted by cate shin
사용자 삽입 이미지
점심때 요즘 밖에 나가지 않는다..

밥먹기 귀찮아서도 있지만.. 조용히 생각할 시간이 필요하다는...

이 커피..당췌 몇잔째냐 ㅡㅡ;;;


사용자 삽입 이미지

내 pc가만히 멍때리기....

cmd 화면 사시될때까지 쳐다보기....

사용자 삽입 이미지

내자리 옆 아래 내려다 보기..

**난 고소공포증이 심해서 이런거 보면 바로 잠깨버린다 ㅠ0ㅠ







사용자 삽입 이미지

그리고 졸릴때 꼭 필요한 레몬펜 쿠션~~

뒷면이 극세사라  부들부들한것이.. 껴안고 부비기 딱 좋으심..

근데..이거 빨아야되는데 ㅡㅡ;;

쿠션!! 주말에 빨아줄게 ㅠ0ㅠ  피죤 뿌려서 ㅎㅎ

크리에이티브 커먼즈 라이선스
Creative Commons License
이올린에 북마크하기(0) 이올린에 추천하기(0)
Posted by cate shin
사용자 삽입 이미지
개인적으로 이사진이 참 맘에 들어서 ㅋㅋㅋ

초대권 12장 드립니다.

방명록에 답글로 줄서신 순서대로 드립니다.

메일올려주시면 감쟈~~

자~~ 뛰어오세욤 !!
크리에이티브 커먼즈 라이선스
Creative Commons License
이올린에 북마크하기(0) 이올린에 추천하기(0)
Posted by cate shin

사용자 삽입 이미지


In A Blink

JavaScript being pulled from the server after the page has loaded.


Technical Story

Devi's concerned about initial user experience, because her new website requires lots of Javascript. She refactors the application, extracting out a few Javascript modules. The initial page load is now much faster, because only a bare-bones initialisation module is pulled down, with the other modules loaded only when they're needed.


Problem

How can you deploy lots of Javascript code?


Forces

  • Ajaxian applications make heavy use of Javascript. Richer browser behaviour means more script code must be downloaded.
  • Downloading Javascript has a performance impact. Interaction cannot fully begin until all initial Javascript has been loaded.
  • Bandwidth is also a concern with heavy Javascript content. Often, not all Javascript that's loaded is actually used, leading to a waste of bandwidth.


Solution

Download Javascript as and when required, instead of downloading it all on page load. This is a "lazy loading" approach applied to Javascript, and has several benefits:

  • Initial page load is faster.
  • Overall bandwidth usage is less, since only Javascript that's required is used.
  • Deployment is easier as the code takes care of pulling in Javascript, with the coder only ensuring enough is there to kick the process off.
  • You can produce snippets of Javascript on the fly - effectively sending back a kind of "behaviour message" advising the browser on its next action. This is a variant of the core pattern described at the end of this section.
  • You can bypass the standard "same-domain" policy that normally necessitates a Cross-Domain Proxy. Provided a server exposes a segment of valid Javascript, it can be extracted by the browser.

Conventionally, best practice has been to include Javascript unobtrusively - by including it in one or more script tags.

  <html>
    <head>
      <script type="text/javascript" src="search.js"></script>
      <script type="text/javascript" src="validation.js"></script>
      <script type="text/javascript" src="visuals"></script>
    </head>
    ...
  </html>

On-Demand Javascript builds on this approach to suggest just a minimal initialisation module in the initial HTML:

  <html>
    <head>
      <script type="text/javascript" src="init.js"></script>
    </head>
    ...
  </html>

The initialisation module declares whatever behaviour is required to start up the page and perhaps enough to cover typical usage. In addition, it must perform a bootstrapping function, pulling down new Javascript on demand.

So how do you load Javascript after the page has loaded? One way is with an XMLHttpRequest Call. The browser can easily accept a Javascript response and evaluate it. Any code not inside a function will be executed immediately. To add new functionality for later on, the Javascript can add directly to the current window or to an object that's already known to exist. For example, the following can be sent:

 self.changePassword = function(oldPassword, newpassword) {
   ...
 }

The callback function just needs to treat the response as plain-text and pass it to eval(). A warning: here again, asynchronicity rears its ugly head. You can't assume the new function will be available immediately. So don't do this:

 if (!self.changePassword) {
   requestPasswordModuleFromServer();
 }
 changePassword(old, new) // Won't work the first time because
                          // changePassword's not loaded yet.

You either need to make a synchronous call to the server, explicitly make the call in the response handler, or use a closure callback - either manually or using a continuation transformer such as Narrative JavaScript or djax. Note that you can't just add a loop to keep checking for the new function, due to the single-threaded nature of Javascript.

A less obtrusive way to do the same thing involves DOM Manipulation. Simply insert a suitable script element into the DOM and the Javascript will be loaded. It can be a child of either the head or body and its src property must be pointing to a Javascript URL. There are several differences with XMLHttpRequest:

  • The Javascript will automatically be evaluated in much the same way as Javascript linked in the static HTML is evaluated when the <script> tag is first encountered. You can declare a bare function or variable without adding it to the window.
  • You can load Javascript from external domains.
  • The URL points to a specific Javascript resource. With XMLHttpRequest, there's more flexibility: you can, for example, send several Javascript snippets inside different XML nodes.
  • The DOM is affected in a different way. Even if the behaviour is transient, the script will be added to the DOM, whereas it would disappear after an XMLHttpRequest callback eval'd it.

(Watch for compatibility. See http://www.howtocreate.co.uk/loadingExternalData.html)

  • Inserting script element into the DOM means that if the file is cached in the browser then the cache is used. This is not possible with XMLHttpRequest.

There's a variant of the pattern I'll call Javascript Response in reference to the HTML Response pattern. The standard pattern refers to the situation where you're downloading a new set of functions, classes, and variables. In reality, you're just adding new members to the DOM - some other code will then invoke it. In Javascript Response, you grab a snippet of Javascript and eval it - the script is not wrapped inside a function (although it may define some functions that it calls). Under this variant, then, the browser is asking the browser what to do next. Whereas in the standard pattern, the browser knows what to do, but not how to do it.

One important application is with JSON Messages. Being standard Javascript, they can be downloaded using On-Demand Javascript, which is a convenient way to transfer semantic content, i.e. a self-contained object. Because Javascript can be pulled from third-party sources, this provides a mechanism for transferring semantic content from an external server into the browser, and without a Cross-Domain Proxy. Some Web Services, designed for public browser-based usage, therefore output JSON Messages.

If you are exposing a JSON API from your server for external browsers to use, you should be aware of some important security concerns. Any JSON-based services that rely on cookie-based authentication are vulnerable. Otherwise, you allow a malicious website to make cross-domain calls on behalf of the user, to a JSON service. This is unlike XMLHttpRequest Calls, which can't cross domains and IFrame Calls, where external domain details can't be accessed by the parent application. With JSON, there is no such protection...by redefining the ways of Javascript, such as rewriting the Array constructor, hackers from evil.com can submit an authenticated JSON call to bank.com, and then do what they like with the response, e.g. upload it back to their servers. To prevent this: (a) ensure JSON is used to serve only public data, i.e. that which requires no cookie-based authentication; OR (b) if your web app relies on calling cookie-based JSON services from your own server, make the services POST-based, so that they can't be invoked from script tag inclusion (which always uses GET). This means your browser script will have to issue a POST-based XMLHttpRequest Call and eval() the response. Fortunately, a browser script from an external server won't be allowed to issue the same request.

Real-World Examples

Ajile

Ajile is a browser-independent JavaScript extension that provides on-demand script loading, namespace, import and dependency-management support.

Ajile provides cross-domain script loading via dynamic script insertion circumventing the Same Origin Policy problem that limits XMLHttpRequest-based solutions.

  Load    ("http://cross.domain/script.js");  // Load an arbitrary script from an external domain.
  Import  ("my.namespace.*");                 // Load & provide short-name access to all my.namespace modules.
  Include ("my.namespace.Module");            // Load my.namespace.Module
  ImportAs("Mine", "my.namespace.Module");    // Load my.namespace.Module as Mine (importing with aliases)

Ajile further enhances the loading process by providing configurable automatic script loading. This feature allows web pages to be associated with unique and/or shared scripts that are automatically loaded when Ajile is initialized. This automatic loading reduces the number scripts explicitly listed within web pages to just one, Ajile's:

  <script type="text/javascript" src="path/to/com.iskitz.ajile.js"></script>

By acting as a page's controller, Ajile allows script changes to be made independently of the host page. This simplifies page maintenance and improves team efficiency by allowing designers to work in script-free HTML while developers work in a pure scripting environment.

Persevere

Persevere Client is a persistent object mapping JavaScript framework. Persevere uses a persistent object model where the logic for applications can be defined within the persisted objects. The persisted objects as well as the JavaScript functions within are loaded on demand using the JSPON data format (an extension of JSON). Persevere uses JavaScript Strands for continuations, and by utilizing continuations, Persevere can do true inline on-demand loading of JavaScript and data without making synchronous (locking) remote calls. On-demand loading is done transparently as data is needed. Persevere supports lazy loading with standard JavaScript syntax, so the following is an example of referencing a persisted object and function with Persevere:

  myobj.anotherObject.render();

Persevere will transparently retrieve the object referred to by "anotherObject" and the render function if they have not been loaded then execution will continue inline. prediction for object transfers.

MapBuilder

MapBuilder is a framework for mapping websites. It uses On-Demand Javascript to reduce the amount of code being downloaded. The application is based on a Model-View-Controller paradigm. Model information is declared in an XML file, along with Javascript required to load corresponding widgets. When the page starts up, only the required Javascript is downloaded, instead of the entire code base. This is therefore a partial implementation of this pattern; it does ensure that only the minimal subset of Javascript is ever used, but it doesn't load pieces of the code in a lazy, on-demand, style.

Dojo Package System

Dojo is a comprehensive framework aiming to simplify Javascript development. As such, it provides a number of scripts, of which an individual project might only use a subset. To manage the scripts, there's a Java-like package system, which lets you pull in new Javascript as required. You only need include a single Javascript file:

  <script src="dojo.js" type="text/javascript">

You then pull in further packages on demand like this:

  dojo.require("dojo.aDojoPackage");

will download all relevant Javascript modules in dojo.aDojoPackage. The precise set of modules is defined by the dojo.aDojoPackage author, and can be made dependent on the calling environment (whether browser or command-line).

JSAN Import System

The JavaScript Archive Network (JSAN) is an online repository of scripts. As well, it includes a library for importing Javascript modules, also a convention similar to Java. The following call:

 JSAN.use('Module.To.Include');

is mapped to Module/To/Include.js. JSAN.includePath defines all the possible top-level directories where this path can reside. If the includePath is ["/", "/js"], JSAN will look for /Module/To/Include and /js/Module/To/Include.

twoBirds full AJAX - everything on demand

This AJAX system is providing on-demand web-object functionality. In addition to load the .js file on demand, it also loads .html.tpl and .css files dynamically into the browser cache structure. A given twoBirds web-object has an init() function, that checks whether all files needed are present in the cache, if not waits for them to be loaded, and then calculates the html code of the element to be included in the DOM model. The following call:

tb.element.show( 'target div id', '<module>', '<element>' );

will load and display an element on the webpage in the given DIV element. twoBirds includes a modular site structure based on module directories.

Since a twoBirds web-object may include other twoBirds web objects, the site overall complexity level is unlimited, still allowing quality management of the code.

As of Mar 31st 2007 twoBirds V2.0.0 has been declared stable, see [1] for the prototype. Contact the programmer frank dot thuerigen -at- phpbuero justAnotherDot de if you want to get a copy of the lib, since system documentation and his ever-forgotten HP are "work in progress" right now.

Learnhanzi flashcards

Flashcards for learning Chinese characters Chinese characters flashcards. It uses On-Demand Javascript to load the main script as well as to continually load new character data and images. It's connected to a database of 7000+ characters.


Refactoring Illustration

Introducing On-Demand Javascript to the Wiki Demo

In the Basic wiki Demo, all Javascript is downloaded at once. But many times, users will only read from the wiki - why download the code to write to it? So this demo refactors to [On-Demand Javascript], in three stages:

1. The uploadMessage function is extracted to a second Javascript file, upload.js. 2. A further refactoring pulls in the upload.js file only if and when an upload occurs. This version uses the DOM-morphing approach. 3. In yet another refactoring, the DOM-morphing approach is substituted with the XMLHttpRequest approach.

Separate Javascript: Extracting upload.js

In the first refactoring, the upload function is simply moved to a separate Javascript file. The initial HTML includes the new file.

  <script type="text/javascript" src="wiki.js"></script>
  *** <script type="text/javascript" src="upload.js"></script> ***

The new upload.js now contains the uploadMessage function. Reflecting the separation, a couple of parameters were introduced to decouple the function from the main wiki script.

 function uploadMessages(pendingMessages, messageResponseHandler) {
   ...
 }

The calling code is almost the same as before:

 uploadMessages(pendingMessages, onMessagesLoaded);

We've thus far gained a bit of modularity, but no boost to performance, since both files must be downloaded on startup.

DOM-Based On-Demand Javascript

This refactoring and the next both achieve On-Demand Javascript, in different ways. Neither approach is intrinsically superior - each approach has its own characteristics, as discussed in the Solution above.

With On-Demand Javascript, the upload.js is no longer required on startup, so it's reference no longer appears in the initial HTML, leaving just the main module, wiki.js.

 <script type="text/javascript" src="wiki.js"></script>

To this file, a new function has been added to download the script. To avoid downloading the script multiple times, a check is made against uploadMessages, the function that's downloaded on demand. It adds a script element to the document's head, initialised with the upload.js URL and a standard Javascript type attribute. This new DOM element is at the heart of DOM-based On-Demand Javascript.

 function ensureUploadScriptIsLoaded() {
   if (self.uploadScript) { // Already exists
     return;
   }
   var head = document.getElementsByTagName("head")[0];
   script = document.createElement('script');
   script.id = 'uploadScript';
   script.type = 'text/javascript';
   script.src = "upload.js";
   head.appendChild(script);
 }

If you are going to fetch data from some script every interval, it is necessary to clean up after yourself before creating new DOM node with new script. In other case your DOM will grow lineary with time and consume more and more RAM. Modified previous example, which cleans up previous script before creating new call:

 function periodicChecker() {
   var old = document.getElementById('uploadScript');
   if (old != null) {
     old.parentNode.removeChild(old);
     delete old;
   }
   var head = document.getElementsByTagName("head")[0];
   var script = document.createElement('script');
   script.id = 'uploadScript';
   script.type = 'text/javascript';
   script.src = "upload.js";
   head.appendChild(script);
 }

The calling script just has to call this function. However, as mentioned in the Solution, it's downloaded asynchronously, so a check must be made here too.

 ensureUploadScriptIsLoaded();
 if (self.uploadMessages) { // If not loaded yet, wait for next sync
   uploadMessages(pendingMessages, onMessagesLoaded);
   ....

In most cases, the test will actually fail the first time, because the download function will return before the script's been downloaded. But in this particular application, that doesn't actually matter much - the whole synchronisation sequence is run every five seconds anyway. If the upload function isn't there yet, it should be there in five seconds, and that's fine for our purposes. If desired, we could be more aggressive - for instance, the script could be downloaded as soon as an edit begins.

XMLHttpRequest-Based On-Demand Javascript

The DOM manipulation technique is refactored here to use an XMLHttpRequest Call instead, where a server call retrieves upload.js and eval's it. As with the previous version, upload.js no longer appears in the initial HTML. Also, the invocation of ensureUploadScriptIsLoaded remains as before. The initial script - wiki.js differs only in the implementation of the Javascript retrieval. The text response is simply passed to eval.

 function ensureUploadScriptIsLoaded() {
   if (self.uploadMessages) { // Already exists
     return;
   }
   ** ajaxCaller.getPlainText("upload.js", function(jsText) { eval(jsText); }); **
 }

The actual Javascript must also change. If it simply defined a global function like before, i.e.:

 function(pendingMessages, messageResponseHandler) {
   ...
 }

the function would die when the evaluation completes. Instead, we can achieve the same affect by altering the browser window object (self).

 self.uploadMessages = function(pendingMessages, messageResponseHandler) {
   ...
 }


Related Patterns

HTML Response

The Javascript Response variant of this pattern is a companion to HTML Response and follows a similar server-centric philosophy in which it is the server-side that pushes instructions to the browser.

Predictive Fetch

Apply Predictive Fetch to On-Demand Javascript by downloading Javascript when you anticipate it will soon be required.

Browser-Side Cache

The nature of Javascript deployment means that a form of browser-side caching occurs naturally. That is, the results of calls are usually retained by virtue of the fact they automatically add new functions to the DOM.

Multi-Stage Download

On-Demand Javascript is a variant of Multi-Stage Download. The emphasis in Multi-Stage Download is on downloading semantic and display content rather than Javascripts. In addition, that pattern is more about downloading according to a pre-scheduled sequence rather than downloading on demand.


Visual Metaphor

If you watch someone learning to use a new product, their experience will usually mimic On-Demand Javascript. They'll read the bare minimum, if anything, and get started playing with it. When they get stuck, they'll consult the instructions, but only enough to get over the next hurdle.


Want to Know More?

Dynamic data using the DOM and Remote Scripting A tutorial by Thomas Brattli.

크리에이티브 커먼즈 라이선스
Creative Commons License
Posted by cate shin

XmlHttpReques 2

PROGRAMMING 2008/05/15 11:13
사용자 삽입 이미지


XmlHttpRequest 반복설정

  1. <html>
    1. <head>
      1. <script type=”text/javascript” src=”xmlhttp.js”></script>
      2. <script type=”text/javascript”>  
        1. var AJAX_URL=”http://www.fettig.net/playground/ajax-subdomain/ajaxdata.php”;
        2. function gotResult(status, headers, result) {
          1. var oldDomain = document.domain;
          2. document.domain = “fettig.net”;
          3. window.parent.gotTime(result);
          4. document.domain = oldDomain;
          5. setTimeout(getTime, 1000);
        3. }
        4. function getTime(){    
          1. getUrl(AJAX_URL, gotResult);
        5. }
        6. getTime();
        7. </script>
      3. </head>
    2. </html>
test2-iframe.html에서, test3-iframe.html에 있는 gotResult 함수는 document.domain을 fetting.net로 설정하고 window.parent.gotTime을 호출함.

**parent frame에 접근을 가능케 하기 위해 fetting.net 으로 설정하는것임
크리에이티브 커먼즈 라이선스
Creative Commons License

'PROGRAMMING' 카테고리의 다른 글

XmlHttpReques 2  (0) 2008/05/15
XmlHttpReques 1  (0) 2008/05/15
Posted by cate shin

XmlHttpReques 1

PROGRAMMING 2008/05/15 11:11
사용자 삽입 이미지


http://fettig.net/weblog/2005/11/28/how-to-make-xmlhttprequest-connections-to-another-server-in-your-domain/

subdomain의 페이지의 full URL과 함께하는 XHR

  1. <html>
  2. <head>
    1. <script type=”text/javascript” src=”xmlhttp.js”></script>
    2. <script type=”text/javascript”>
      1. var AJAX_URL=”http://www.fettig.net/playground/ajax-subdomain/ajaxdata.php”;
      2. function getTime(){
        1. getUrl(AJAX_URL, gotTime);
      3. }
      4. function gotTime(status, headers, result) {
        1. document.getElementById(’time’).innerHTML = result;
        2. setTimeout(getTime, 1000)
        3. }
      5. window.onload = getTime;
    3. </script>
  3. </head>
  4. <body>
  5. <div id=”time”>
  6. </div>
  7. </body>
  8. </html>

크리에이티브 커먼즈 라이선스
Creative Commons License

'PROGRAMMING' 카테고리의 다른 글

XmlHttpReques 2  (0) 2008/05/15
XmlHttpReques 1  (0) 2008/05/15
Posted by cate shin