posted by 지니우스 2017. 6. 27. 14:01

출처 QuirksMode | QuirksMode
원문 http://blog.naver.com/box252/220350058395

1.javascript 사용의 일반적인 구문


일반적으로 우리는 자바스크립트를 head에 선언하여 사용합니다.


<일반적인 구문>

<head>

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

</head>


하지만 HTML문서가 스크립트 파일을 만났을 때 DOM의 로딩은 정지가 된 상태로 백지화면만 보여지게 됩니다.

그래서 생각해낸 방법이 해당 DOM아래 스크립트를 위치 시키는거였습니다.


<DOM의 아래에 스크립트 위치>

<div>

  //Function.js 라이브러리를 활용한 구문

</div>

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



2.defer와 async 


defer와 async속성은 스크립트 구문에 사용하며 아래 그림으로 축약 할 수 있습니다.


 


일반적인 스크립트 구문은 HTML파싱중 스크립트 구문을 만나면 전송 받고 실행을 합니다.

defer 속성을 사용시에는 파싱과 스크립트를 동시에 전송받고 파싱이 완료된 후 실행합니다.

async 속성을 사용시에는 파싱과 스크립트를 동싯에 전송받지만 실행시에는 파싱을 멈춥니다.


<defer, async>

<head>

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

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

</head>


※ XHTML문서에서는 defer="defer" 형태로 사용해야 합니다.


posted by 지니우스 2017. 6. 26. 14:21

참고: https://stackoverflow.com/questions/4797050/how-to-run-process-as-background-and-never-die



1안) nohup을 사용. 출력을 /dev/null 로 내보내기.


nohup node server.js > /dev/null 2>&1 &

  1. nohup means: Do not terminate this process even when the stty is cut off.
  2. > /dev/null means: stdout goes to /dev/null (which is a dummy device that does not record any output).
  3. 2>&1 means: stderr also goes to the stdout (which is already redirected to /dev/null). You may replace &1 with a file path to keep a log of errors, e.g.: 2>/tmp/myLog
  4. & at the end means: run this command as a background task.


2안) pm2 패키지 설치해서 사용하기.


Nohup and screen offer great light solutions to running Node.js in the background. Node.js process manager (PM2) is a handy tool for deployment. Install it with npm globally on your system:

npm install pm2 -g

to run a Node.js app as a daemon:

pm2 start app.js




posted by 지니우스 2017. 5. 31. 13:18

출처: http://mainia.tistory.com/2428


1. escape(), unescape() 함수


▼ 아스키문자에 해당하지 않는 문자들은 모두 유니코드 형식으로 변환해 줍니다. 그러니까 16진수 형태로 바꿔주는 것이죠. 표기법은 1바이트일때 %XX 이며 2바이트 일때는 %uXXXX 입니다. 앞에 u 가 하나 더 붙죠. 그리고 16진수에서는 문자 2개가 하나의 바이트를 이룹니다. 


[입력]

document.write(escape("인코딩, escape"));


[출력]

%uC778%uCF54%uB529%2C%20escape



2. encodeURI() 함수


 encodeURI 는 URL 주소표시를 나타내는 앞자리 특수문자는 인코딩하지 않습니다. 인코딩 하지 않는 문자는 ": ; / = ? &" 입니다. 주소를 통해 넘기는 파라미터를 인코딩할때 사용합니다.


[입력]

document.write(escape("http://녹두장군.com")+ "<br/>");

document.write(encodeURI("http://녹두장군.com"));


[출력]

http%3A//%uB179%uB450%uC7A5%uAD70.com

http://%EB%85%B9%EB%91%90%EC%9E%A5%EA%B5%B0.com



3. encodeURLComponent() 함수


 encodeURI 와 달리 주소를 나타내는 특수문자도 인코딩을 하게 됩니다. 모든 문자를 인코딩 하기 때문에 경로를 나타내는 /file/exe/index 값이 있다면 "/" 도 인코딩하기 하게 됩니다. 이렇게 되면 서버에서는 인식을 못합니다. 이럴때는 encodeURI 를 사용해야 합니다. 다시 디코딩을 하시려면 decodeURIComponent() 함수를 사용합니다.


[입력]

document.write(encodeURI("http://mainia.tistory.com?id=홍길동&phone=010") + "<br/>");

document.write(encodeURIComponent("http://mainia.tistory.com?id=홍길동&phone=010"));


[출력]

http://mainia.tistory.com?id=%ED%99%8D%EA%B8%B8%EB%8F%99&phone=010

http%3A%2F%2Fmainia.tistory.com%3Fid%3D%ED%99%8D%EA%B8%B8%EB%8F%99%26phone%3D010