<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Javascript | Nerdpress.org</title>
	<atom:link href="https://nerdpress.org/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>https://nerdpress.org</link>
	<description>...dev, tech problems and solutions.</description>
	<lastBuildDate>Fri, 12 Apr 2024 08:01:50 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>Monorepo with NPM workspaces</title>
		<link>https://nerdpress.org/2024/04/12/monorepo-with-npm-workspaces/</link>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Fri, 12 Apr 2024 08:01:50 +0000</pubDate>
				<category><![CDATA[JS]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[NPM]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Monorepo]]></category>
		<category><![CDATA[nodejs]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=3300</guid>

					<description><![CDATA[<p>I recently converted a project into a Monorepo.I had a cli part and an Astro StaticSiteGenerator part. At some point I felt like these parts would be entangled too much so I decided to separate them. Since they were still related they should stay in one repo but have their own dependencies and separate processes. &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2024/04/12/monorepo-with-npm-workspaces/" class="more-link">Continue reading<span class="screen-reader-text"> "Monorepo with NPM workspaces"</span></a></p>
The post <a href="https://nerdpress.org/2024/04/12/monorepo-with-npm-workspaces/">Monorepo with NPM workspaces</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>I recently converted a project into a Monorepo.<br />I had a cli part and an Astro StaticSiteGenerator part. <br />At some point I felt like these parts would be entangled too much so I decided to separate them. Since they were still related they should stay in one repo but have their own dependencies and separate processes. I still could have kept this in one Astro project with a cli folder but so it feels cleaner structured.</p>



<p>I chose NPM as my package manager since it comes bundled with node and so I decided to try out <a href="https://docs.npmjs.com/cli/v7/using-npm/workspaces" title="">NPM workspaces</a> as my MonoRepo approach.</p>



<p>So here are my takeaways</p>



<span id="more-3300"></span>



<p><strong>1.  Setup</strong></p>



<ul class="wp-block-list">
<li>The NPM workspaces Monorepo has one root dir with one package.json which defines the workspaces, but besides this it is more or less empty. The package.json defines a workspace directory which contains the sub projects. <br />As of now you can&#8217;t use <code>npm init</code> for this but have to create the main package.json manually.</li>
</ul>


<pre class="wp-block-code"><span><code class="hljs language-javascript">  <span class="hljs-string">"name"</span>: <span class="hljs-string">"workspaces-example"</span>,
  <span class="hljs-string">"workspaces"</span>: &#91;
    <span class="hljs-string">"packages/*"</span>
  ],</code></span></pre>


<figure class="wp-block-image size-full"><a href="https://nerdpress.org/wp-content/uploads/2024/04/npm-workspaces-directories.png"><img fetchpriority="high" decoding="async" width="258" height="210" src="https://nerdpress.org/wp-content/uploads/2024/04/npm-workspaces-directories.png" alt="" class="wp-image-3303"/></a></figure>



<ul class="wp-block-list">
<li>The sub projects each have their own package.json with all necessary dependencies for this specific project. The sub projects can be initialised by <code>npm init -w packages/cli</code></li>



<li>To add dependencies you can add the workspace to the <code>npm add</code> command and the dependency will be added to the respective package.json:<br /><code>npm add commander -w packages/cli</code><br />To install dependencies, run <code>npm i</code> from the root directory. This will install all deps of all workspaces in a node_modules folder in the root directory, but none in the projects in the workspaces folder. This already is a win because it will avoid having dependency duplettes.<br />However if you have conflicting versions of the same dependency in your packages, you will have a separate node_modules directory with the only the specific version for this single package.</li>
</ul>



<figure class="wp-block-image size-full"><a href="https://nerdpress.org/wp-content/uploads/2024/04/npm-workspaces-conflicting-versions-directories-1.png"><img decoding="async" width="272" height="354" src="https://nerdpress.org/wp-content/uploads/2024/04/npm-workspaces-conflicting-versions-directories-1.png" alt="" class="wp-image-3306" srcset="https://nerdpress.org/wp-content/uploads/2024/04/npm-workspaces-conflicting-versions-directories-1.png 272w, https://nerdpress.org/wp-content/uploads/2024/04/npm-workspaces-conflicting-versions-directories-1-231x300.png 231w" sizes="(max-width: 272px) 100vw, 272px" /></a></figure>



<p><br /><strong>2. Development</strong></p>



<ul class="wp-block-list">
<li>Updating dependencies can happen just like adding dependencies:<br /><kbd>npm update commander -w packages/cli</kbd></li>



<li>When you need different versions of a dependency in your workspaces, NPM will create a new node_modules folder in the one divergating workspace with only the dependency where you have the different version.</li>



<li>When you need to share code between workspaces you can import code from one package of the workspaces in another package just as a normal dependency from the NPM registry. <br />For example when you want to share types in a typescript project you can add a types workspace and just import in the other workspaces files. <br /><code>import {Name} from "types";</code></li>



<li>It is probably good practice to add shortcut scripts to your main package.json to run commands of your workspaces. So you don&#8217;t need to change to the workspaces directory, which is of course still possible.</li>
</ul>


<pre class="wp-block-code"><span><code class="hljs language-javascript">  <span class="hljs-string">"scripts"</span>: {
    <span class="hljs-string">"hello-cli"</span>: <span class="hljs-string">"npm --workspace=@workspaces-example/cli run hello"</span>,
    <span class="hljs-string">"hello-web"</span>: <span class="hljs-string">"npm --workspace=@workspaces-example/web run hello"</span>
  }
</code></span></pre>


<p><strong>3. Deploy</strong></p>



<ul class="wp-block-list">
<li>Deploying from a Monrepo needs to take the different packages into account, which need to be deployed separately but from the same CI config. <br />For Github Actions i used a path directive which changes to the package directory and runs instructions there. <br /><code>with: <br />  path: packages/astro</code></li>



<li>Other prefabricated actions like f.e. <kbd>actions/deploy-pages</kbd> have a <br /><kbd>working-directory: ./packages/astro</kbd> <br />directive which have the same effect.</li>
</ul>



<p>You can check out the example project here: <a href="https://github.com/ivoba/npm-workspaces-example" target="_blank" rel="noopener" title="">https://github.com/ivoba/npm-workspaces-example</a></p>



<p>One probably does not necessarily need a Monorepo for this example, but it is good to know that Monorepos are quite simple to achieve just with NPM, in case you need to.</p>The post <a href="https://nerdpress.org/2024/04/12/monorepo-with-npm-workspaces/">Monorepo with NPM workspaces</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Migrating from gulp to esbuild</title>
		<link>https://nerdpress.org/2021/07/23/migrating-from-gulp-to-esbuild/</link>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Fri, 23 Jul 2021 15:06:46 +0000</pubDate>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Frontend]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[esbuild]]></category>
		<category><![CDATA[gulp]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[sass]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=3066</guid>

					<description><![CDATA[<p>Esbuild is the new cool kid in the bundler world.It is super fast since its written in Go and comes with a lot of builtin features for modern frontend development. So i wanted to try it myself and migrated a former gulp build to esbuild. But as it showed the gulp build was not so &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2021/07/23/migrating-from-gulp-to-esbuild/" class="more-link">Continue reading<span class="screen-reader-text"> "Migrating from gulp to esbuild"</span></a></p>
The post <a href="https://nerdpress.org/2021/07/23/migrating-from-gulp-to-esbuild/">Migrating from gulp to esbuild</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p><a href="https://esbuild.github.io/" target="_blank" rel="noreferrer noopener">Esbuild</a> is the new cool kid in the bundler world.<br />It is super fast since its written in Go and comes with a lot of builtin features for modern frontend development.</p>



<p>So i wanted to try it myself and migrated a former <a href="https://gulpjs.com/" title="https://gulpjs.com/" target="_blank" rel="noreferrer noopener">gulp</a> build to esbuild.</p>



<p>But as it showed the gulp build was not so modern, as it was just Sass and Javascript minification. No ES6, No React, no JSX with inline styles.</p>



<p>So Esbuild was not working out of the box but needed some extra config and the <a href="https://www.npmjs.com/package/esbuild-plugin-sass" target="_blank" rel="noreferrer noopener">Sass plugin</a>.</p>



<p><code>npm i -d esbuild esbuild-plugin-sass</code></p>



<p>Also I had to rewrite the Javascript to use ES6 modules, but this was fortunatly easy.</p>



<span id="more-3066"></span>



<p>When using a plugin we need to create our own build file and configure esbuild to use the Sass plugin.<br />esbuild.js:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: jscript; title: ; notranslate">
const esbuild = require(&#039;esbuild&#039;);
const sassPlugin = require(&#039;esbuild-plugin-sass&#039;);

esbuild.build({
  entryPoints: &#x5B;&quot;main.js&quot;],
  bundle: true,
  minify: true,
  format: &#039;iife&#039;,
  platform: &#039;browser&#039;,
  outfile:&quot;main.min.js&quot;,
  plugins: &#x5B;sassPlugin()]
}).catch((err) =&gt; {
  console.log(err)
})
</pre></div>


<p>Ok, but where are the Sass files now?<br />With ES6 you can import styles and then esbuild &amp; the sassPlugin can follow this path from the entrypoint file and create the CSS file from the source Sass file.</p>



<p>So in main.js import the styles:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: jscript; title: ; notranslate">
import $ from &#039;jquery&#039;
import &#039;./style.scss&#039;
...
</pre></div>


<p>Now you can call the esbuild.js file:</p>



<p><code>node ./esbuild.js</code></p>



<p><em>(Yeah no file watchers here, just manual trigger ;))</em></p>



<p>This will bundle the javascript to main.min.js and also create a main.min.css file.</p>



<p>Then include this in your HTML</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: xml; title: ; notranslate">
&lt;link rel=&quot;stylesheet&quot; href=&quot;/main.min.css&quot;&gt; 
&lt;script src=&quot;/main.min.js&quot;&gt;&lt;/script&gt;
</pre></div>


<p>and you are done. :)</p>The post <a href="https://nerdpress.org/2021/07/23/migrating-from-gulp-to-esbuild/">Migrating from gulp to esbuild</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>bower, require.js, masonry &#038; imagesloaded</title>
		<link>https://nerdpress.org/2014/01/28/bower-require-js-masonry-imagesloaded/</link>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Tue, 28 Jan 2014 17:02:42 +0000</pubDate>
				<category><![CDATA[JS]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bower]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[masonry]]></category>
		<category><![CDATA[requirejs]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=2519</guid>

					<description><![CDATA[<p>Wanna run masonry with imagesloaded in require.js, powered by bower? Try this gist! First create your bower.json file and run bower install Then configure require.js and then code the app: Its scrabbled together from http://masonry.desandro.com/appendix.html and various StackOverflow posts.</p>
The post <a href="https://nerdpress.org/2014/01/28/bower-require-js-masonry-imagesloaded/">bower, require.js, masonry & imagesloaded</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>Wanna run <a href="http://masonry.desandro.com/" target="_blank">masonry</a> with <a href="https://github.com/desandro/imagesloaded" target="_blank">imagesloaded</a> in <a href="http://www.requirejs.org/" target="_blank">require.js</a>, powered by <a href="http://bower.io" target="_blank">bower</a>?</p>
<p>Try this <a href="https://gist.github.com/ivoba/7097270" target="_blank">gist</a>!</p>
<p>First create your bower.json file and run <strong>bower install</strong><br />
<script src="https://gist.github.com/7097270.js?file=bower.json"></script><noscript><pre><code class="language-json json">{
  &quot;name&quot;: &quot;bower-masonry-imagesloaded-requirejs&quot;,
  &quot;version&quot;: &quot;0.0.0&quot;,
  &quot;dependencies&quot;: {
    &quot;requirejs&quot;: &quot;~2.1.8&quot;,
    &quot;jquery&quot;: &quot;~1.10.2&quot;,
    &quot;masonry&quot;: &quot;~3.1.2&quot;,
    &quot;imagesloaded&quot;: &quot;~3.0.4&quot;
  }
}</code></pre></noscript></p>
<p><span id="more-2519"></span></p>
<p>Then configure require.js<br />
<script src="https://gist.github.com/7097270.js?file=main.js"></script><noscript><pre><code class="language-javascript javascript">require.config({
    paths: {
        jquery: &#039;../bower_components/jquery/jquery&#039;,
        eventie: &#039;../bower_components/eventie&#039;,
        &#039;doc-ready&#039;: &#039;../bower_components/doc-ready&#039;,
        eventEmitter: &#039;../bower_components/eventEmitter&#039;,
        &#039;get-style-property&#039;: &#039;../bower_components/get-style-property&#039;,
        &#039;get-size&#039;: &#039;../bower_components/get-size&#039;,
        &#039;matches-selector&#039;: &#039;../bower_components/matches-selector&#039;,
        outlayer: &#039;../bower_components/outlayer&#039;,
        masonry: &#039;../bower_components/masonry&#039;,
        imagesloaded: &#039;../bower_components/imagesloaded&#039;
    }
});</code></pre></noscript></p>
<p>and then code the app:<br />
<script src="https://gist.github.com/7097270.js?file=app.js"></script><noscript><pre><code class="language-javascript javascript">define([&#039;masonry/masonry&#039;, &#039;imagesloaded/imagesloaded&#039;], function(Masonry, imagesLoaded) {
    $(document).ready(function() {
        var container = document.querySelector(&#039;#masonry&#039;);
        imagesLoaded(container, function() {
           var msnry = new Masonry(container, {
               columnWidth: 200,
                gutter: 20,
                itemSelector: &#039;.item&#039;,
                isFitWidth: true
           });
             
       });
    });
});</code></pre></noscript></p>
<p>Its scrabbled together from <a href="http://masonry.desandro.com/appendix.html">http://masonry.desandro.com/appendix.html</a> and various StackOverflow posts.</p>The post <a href="https://nerdpress.org/2014/01/28/bower-require-js-masonry-imagesloaded/">bower, require.js, masonry & imagesloaded</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>JSfiddle Bookmarklet Generator with jQuery &#038; Codemirror</title>
		<link>https://nerdpress.org/2013/03/08/jsfiddle-bookmarklet-generator-with-jquery-codemirror/</link>
					<comments>https://nerdpress.org/2013/03/08/jsfiddle-bookmarklet-generator-with-jquery-codemirror/#comments</comments>
		
		<dc:creator><![CDATA[Max Girkens]]></dc:creator>
		<pubDate>Fri, 08 Mar 2013 11:41:59 +0000</pubDate>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[bookmarklet]]></category>
		<category><![CDATA[CodeMirror]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jsfiddle]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=2410</guid>

					<description><![CDATA[<p>This is a little bookmarklet generator i put together this morning: http://jsfiddle.net/QMeuV/1/embedded/result/ Its hosted on jsfiddle.net and enables you to create Bookmarklets which use jQuery based on the code i found here: http://coding.smashingmagazine.com/2010/05/23/make-your-own-bookmarklets-with-jquery/ It also features Javascript Syntax Highlighting using http://codemirror.net/. *UPDATE* this tool now (also) lives on https://github.com/gherkins/bookmarklet-generator</p>
The post <a href="https://nerdpress.org/2013/03/08/jsfiddle-bookmarklet-generator-with-jquery-codemirror/">JSfiddle Bookmarklet Generator with jQuery & Codemirror</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>This is a little bookmarklet generator i put together this morning:</p>
<p><a href="http://jsfiddle.net/QMeuV/1/embedded/result/">http://jsfiddle.net/QMeuV/1/embedded/result/<span id="more-2410"></span></a></p>
<p><a href="https://nerdpress.org/wp-content/uploads/2013/03/Bildschirmfoto-2013-03-08-um-12.24.55.png"><img decoding="async" class="alignnone size-medium wp-image-2411" alt="Bildschirmfoto 2013-03-08 um 12.24.55" src="https://nerdpress.org/wp-content/uploads/2013/03/Bildschirmfoto-2013-03-08-um-12.24.55-300x224.png" width="300" height="224" srcset="https://nerdpress.org/wp-content/uploads/2013/03/Bildschirmfoto-2013-03-08-um-12.24.55-300x224.png 300w, https://nerdpress.org/wp-content/uploads/2013/03/Bildschirmfoto-2013-03-08-um-12.24.55-1024x767.png 1024w, https://nerdpress.org/wp-content/uploads/2013/03/Bildschirmfoto-2013-03-08-um-12.24.55.png 1559w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>Its hosted on <a href="http://jsfiddle.net/">jsfiddle.net</a> and enables you to create Bookmarklets which use jQuery based on the code i found here:<br />
<a href="http://coding.smashingmagazine.com/2010/05/23/make-your-own-bookmarklets-with-jquery/">http://coding.smashingmagazine.com/2010/05/23/make-your-own-bookmarklets-with-jquery/</a></p>
<p>It also features Javascript Syntax Highlighting using <a href="http://codemirror.net/">http://codemirror.net/</a>.</p>
<p>*UPDATE*<br />
this tool now (also) lives on <a href="https://github.com/gherkins/bookmarklet-generator">https://github.com/gherkins/bookmarklet-generator</a></p>The post <a href="https://nerdpress.org/2013/03/08/jsfiddle-bookmarklet-generator-with-jquery-codemirror/">JSfiddle Bookmarklet Generator with jQuery & Codemirror</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
					<wfw:commentRss>https://nerdpress.org/2013/03/08/jsfiddle-bookmarklet-generator-with-jquery-codemirror/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>mashcloud.net &#8211; mashup soundcloud audio tracks</title>
		<link>https://nerdpress.org/2013/01/24/mashcloud-net-mashup-soundcloud-audio-tracks/</link>
		
		<dc:creator><![CDATA[Max Girkens]]></dc:creator>
		<pubDate>Thu, 24 Jan 2013 20:08:28 +0000</pubDate>
				<category><![CDATA[API]]></category>
		<category><![CDATA[Express]]></category>
		<category><![CDATA[Frontend]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[socket.io]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[sockets]]></category>
		<category><![CDATA[soundcloud]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=2359</guid>

					<description><![CDATA[<p>mashcloud.net is an experiment on collaborative realtime audio editing and music creation. I did the project within the frame of  my BA thesis in audio production last year. As I moved the code to github this week, I wanted to give a quick overview of the project and its technical underlyings, just in case someone might &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2013/01/24/mashcloud-net-mashup-soundcloud-audio-tracks/" class="more-link">Continue reading<span class="screen-reader-text"> "mashcloud.net &#8211; mashup soundcloud audio tracks"</span></a></p>
The post <a href="https://nerdpress.org/2013/01/24/mashcloud-net-mashup-soundcloud-audio-tracks/">mashcloud.net – mashup soundcloud audio tracks</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p><a href="http://mashcloud.net/">mashcloud.net</a> is an experiment on collaborative realtime audio editing and music creation. <br />I did the project within the frame of  my BA thesis in audio production last year.</p>
<p>As I moved the code to <a href="https://github.com/gherkins/mashcloud">github</a> this week, I wanted to give a quick overview of the project and its technical underlyings, just in case someone might be interested :)</p>
<p><span id="more-2359"></span>As the title of this post might already suggest, its about selecting and layering loops from audiofiles hosted on <a href="http://soundcloud.com">soundcloud.com</a> and thereby creating new music.</p>
<p><a href="https://nerdpress.org/2013/01/24/mashcloud-net-mashup-soundcloud-audio-tracks/bildschirmfoto-2013-01-24-um-20-46-08/" rel="attachment wp-att-2363"><img decoding="async" class="alignnone size-medium wp-image-2363" alt="Bildschirmfoto 2013-01-24 um 20.46.08" src="https://nerdpress.org/wp-content/uploads/2013/01/Bildschirmfoto-2013-01-24-um-20.46.08-300x174.png" width="300" height="174" srcset="https://nerdpress.org/wp-content/uploads/2013/01/Bildschirmfoto-2013-01-24-um-20.46.08-300x174.png 300w, https://nerdpress.org/wp-content/uploads/2013/01/Bildschirmfoto-2013-01-24-um-20.46.08-1024x593.png 1024w, https://nerdpress.org/wp-content/uploads/2013/01/Bildschirmfoto-2013-01-24-um-20.46.08.png 1050w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>Those collections of layered loops are called a session. Sessions can be created anonymously by everyone and are auto-saved on every action. By distributing the URL of a session other users can join and every action is synced between all users in realtime. <br />(complete mayhem, indeed :)</p>
<p>The application is built with HTML5 and JS w/ <a href="http://jquery.com/">jQuery</a> using the <a href="http://developers.soundcloud.com/docs/api/guide">soundcloud API</a> on the client side and runs on <a href="http://nodejs.org/">node.js</a> &amp; <a href="http://www.mongodb.org/">mongoDB</a> with <a href="http://expressjs.com/">express</a>, <a href="http://socket.io/">socket.io</a> and <a href="http://mongoosejs.com/">mongoose</a> on the server side.</p>
<p>I basically started the project to find out if you could play multiple loops asynchronous and synced with low latency using the <a href="https://dvcs.w3.org/hg/audio/raw-file/tip/webaudio/specification.html">Web Audio API</a> while collaboratively working together with multiple users in realtime. </p>
<p>As that turned out to be not only possible but performed real nicely, the experiment then developed in somewhat of an application and finally got a name and a face.</p>
<p>There&#8217;s a whole lot of things i&#8217;d like to implement / refactor and do when i get some time on my hands, as</p>
<p>&#8211; adding a &#8220;record&#8221; feature to record, save and export created sessions as audiofiles</p>
<p>&#8211; rewriting the client side with <a href="http://backbonejs.org/">backbone.js</a> (as things got a bit messy &#8230;)</p>
<p>&#8211; adding some audio effects to the tracks</p>
<p>&#8211; write some tests</p>
<p>I&#8217;d appreciate any form of contribution as much as any questions or feedback on the project :)</p>
<p>Feel free to check out the live version at <a href="http://mashcloud.net/"> http://mashcloud.net/</a> or the sources at <a href="https://github.com/gherkins/mashcloud">https://github.com/gherkins/mashcloud</a></p>The post <a href="https://nerdpress.org/2013/01/24/mashcloud-net-mashup-soundcloud-audio-tracks/">mashcloud.net – mashup soundcloud audio tracks</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Hosting multiple Express (node.js) apps on port 80</title>
		<link>https://nerdpress.org/2012/04/20/hosting-multiple-express-node-js-apps-on-port-80/</link>
					<comments>https://nerdpress.org/2012/04/20/hosting-multiple-express-node-js-apps-on-port-80/#comments</comments>
		
		<dc:creator><![CDATA[Max Girkens]]></dc:creator>
		<pubDate>Fri, 20 Apr 2012 03:40:31 +0000</pubDate>
				<category><![CDATA[Admin]]></category>
		<category><![CDATA[Express]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[socket.io]]></category>
		<category><![CDATA[vServer]]></category>
		<category><![CDATA[express]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[sockets]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=2144</guid>

					<description><![CDATA[<p>In the last days, i was trying to find a solution hosting multiple Express apps on my vServer the same Server. Starting with Apache and mod_proxy, i ended up with a plain node solution, which i really like. Let&#8217;s take a quick look on some different approaches out there: &#8212;1&#8212; Using apache on port 80 &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2012/04/20/hosting-multiple-express-node-js-apps-on-port-80/" class="more-link">Continue reading<span class="screen-reader-text"> "Hosting multiple Express (node.js) apps on port 80"</span></a></p>
The post <a href="https://nerdpress.org/2012/04/20/hosting-multiple-express-node-js-apps-on-port-80/">Hosting multiple Express (node.js) apps on port 80</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>In the last days, i was trying to find a solution hosting multiple <a href="http://expressjs.com/">Express</a> apps on <del datetime="2012-04-19T00:40:35+00:00">my vServer </del>the same Server.</p>
<p>Starting with <a href="http://www.apache.org/">Apache</a> and <a href="http://httpd.apache.org/docs/2.0/mod/mod_proxy.html">mod_proxy</a>, i ended up with a plain node solution, which i really like.<span id="more-2144"></span></p>
<p><a href="https://nerdpress.org/wp-content/uploads/2012/04/node-http-proxy-haz-colors.png"><img decoding="async" class="alignnone size-full wp-image-2146" title="node-http-proxy-haz-colors" src="https://nerdpress.org/wp-content/uploads/2012/04/node-http-proxy-haz-colors.png" alt="" width="527" height="106" srcset="https://nerdpress.org/wp-content/uploads/2012/04/node-http-proxy-haz-colors.png 527w, https://nerdpress.org/wp-content/uploads/2012/04/node-http-proxy-haz-colors-300x60.png 300w" sizes="(max-width: 527px) 100vw, 527px" /></a></p>
<p>Let&#8217;s take a quick look on some different approaches out there:</p>
<p><strong>&#8212;1&#8212;</strong></p>
<p>Using apache on port 80 as a proxy</p>
<pre class="brush: bash; title: ; notranslate">
ProxyPass /nodeurls/ http://localhost:9000/
ProxyPassReverse /nodeurls/ http://localhost:9000/
</pre>
<p>via <a href="http://stackoverflow.com/questions/6109089/how-do-i-run-node-js-on-port-80">stackoverflow</a></p>
<p>&#8212; no websockets<br />
++ probably the easiest way to integrate with your running AMPP-stack</p>
<p><strong>&#8212;2&#8212;</strong></p>
<p>Using a node.js app on port 80 as a Wrapper for other node apps.</p>
<pre class="brush: jscript; title: ; notranslate">
express.createServer()
  .use(express.vhost('hostname1.com', require('/path/to/hostname1').app)
  .use(express.vhost('hostname2.com', require('/path/to/hostname2').app)
.listen(80)
</pre>
<p>via <a href="http://stackoverflow.com/questions/9332865/how-should-i-organize-multiple-express-servers-on-the-same-system">stackoverflow</a></p>
<p>++ you can use websockets on port 80<br />
&#8212; apps crash/restart/stop globally<br />
&#8211;what about your apache or the like?</p>
<p><strong>&#8212;3&#8212;</strong></p>
<p>Using node.js with node-http-proxy on port 80</p>
<pre class="brush: jscript; title: ; notranslate">
var http = require('http')
, httpProxy = require('http-proxy');

httpProxy.createServer({
  hostnameOnly: true,
  router: {
    //web-development.cc
    'www.my-domain.com': '127.0.0.1:3001',
    'www.my-other-domain.de' : '127.0.0.1:3002'
  }
}).listen(80);

</pre>
<p>++ proxy websockets to any port<br />
&#8212; you might need to move your old web server to another port</p>
<p>The really cool thing about using node-http-proxy is its capability of proxying websockets.<br />
So you can have your apps running independtly on different ports while serving everything to the user over port 80 and use stuff like <a href="http://socket.io/">socket.io</a>.</p>
<p>Since i&#8217;m new to node.js and miles away from beeing a admin, any feedback is highly appreciated :)</p>The post <a href="https://nerdpress.org/2012/04/20/hosting-multiple-express-node-js-apps-on-port-80/">Hosting multiple Express (node.js) apps on port 80</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
					<wfw:commentRss>https://nerdpress.org/2012/04/20/hosting-multiple-express-node-js-apps-on-port-80/feed/</wfw:commentRss>
			<slash:comments>14</slash:comments>
		
		
			</item>
		<item>
		<title>run JavaScript code in PHP 5.3 with the v8js extension</title>
		<link>https://nerdpress.org/2012/03/09/run-javascript-code-in-php-5-3-with-the-v8js-extension/</link>
		
		<dc:creator><![CDATA[Max Girkens]]></dc:creator>
		<pubDate>Thu, 08 Mar 2012 23:14:10 +0000</pubDate>
				<category><![CDATA[JS]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[homebrew]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[pecl]]></category>
		<category><![CDATA[v8js.so]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=2102</guid>

					<description><![CDATA[<p>&#8230;for some reason i needed to get t h i s to work before going to sleep. I&#8217;m running OSX 10.7.3 with macports which usually does the job, but  Google&#8217;s V8 Javascript Engine is not available as a port yet. So&#8230; homebrew to the rescue: installed it: /usr/bin/ruby -e &#34;$(/usr/bin/curl -fsSL https://raw.github.com/gist/323731)&#34; and installed v8 &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2012/03/09/run-javascript-code-in-php-5-3-with-the-v8js-extension/" class="more-link">Continue reading<span class="screen-reader-text"> "run JavaScript code in PHP 5.3 with the v8js extension"</span></a></p>
The post <a href="https://nerdpress.org/2012/03/09/run-javascript-code-in-php-5-3-with-the-v8js-extension/">run JavaScript code in PHP 5.3 with the v8js extension</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>&#8230;for some reason i needed to get <strong><a href="http://php.net/manual/en/book.v8js.php">t h i s</a></strong> to work before going to sleep.</p>
<p>I&#8217;m running OSX 10.7.3 with <a href="http://www.macports.org/">macports</a> which usually does the job, but  <a href="http://code.google.com/p/v8/">Google&#8217;s V8 Javascript Engine</a> is not available as a port yet.<span id="more-2102"></span></p>
<p>So&#8230; <a href="http://mxcl.github.com/homebrew/">homebrew</a> to the rescue:</p>
<p>installed it:</p>
<pre class="brush: bash; title: ; notranslate">
/usr/bin/ruby -e &quot;$(/usr/bin/curl -fsSL https://raw.github.com/gist/323731)&quot;
</pre>
<p>and installed v8</p>
<pre class="brush: bash; title: ; notranslate">
brew install v8
</pre>
<p>wait, this seems <a href="http://www.youtube.com/watch?v=jWI8w9kLAks">too easy</a>.</p>
<p>PECL installed some beta version of the PHP extension.</p>
<pre class="brush: bash; title: ; notranslate">
sudo pecl install channel://pecl.php.net/v8js-0.1.2
</pre>
<p>added</p>
<pre class="brush: bash; title: ; notranslate">extension=v8js.so</pre>
<p>to the php.ini file.</p>
<p>und bitteschön:</p>
<pre class="brush: php; title: ; notranslate">

$v8 = new V8Js();
var_dump($v8-&gt;executeString(&quot;

//hey i'm Javascript Code

//INSIDE PHP !

//wow.
var hello = 'Hallo';

function helloWorld( string ){
return hello + ' ' + string;
}

helloWorld('World');

&quot;));

</pre>
<p>Such things might come in handy one day, <a href="https://plus.google.com/115423703838305233565/posts/VtskgWhB3kV">you know</a>.</p>The post <a href="https://nerdpress.org/2012/03/09/run-javascript-code-in-php-5-3-with-the-v8js-extension/">run JavaScript code in PHP 5.3 with the v8js extension</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>HTML5 &#8211; Sammlung von Ressourcen, Dokus und Browser-Fallbacks</title>
		<link>https://nerdpress.org/2010/11/27/html5-sammlung-von-ressourcen-dokus-und-browser-fallbacks/</link>
					<comments>https://nerdpress.org/2010/11/27/html5-sammlung-von-ressourcen-dokus-und-browser-fallbacks/#comments</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sat, 27 Nov 2010 16:48:43 +0000</pubDate>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[articles]]></category>
		<category><![CDATA[authoring]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[geolocation]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Html5]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[links]]></category>
		<category><![CDATA[localstorage]]></category>
		<category><![CDATA[ressources]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[WebWorker]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=1225</guid>

					<description><![CDATA[<p>Hier mal eine anfänglich kleine Sammlung zum Thema HTML 5 generell &#8211; grob kategorisiert. Vervollständigungen und Streichungen willkommen. Cross Browser Helper Html 5 Validator (en) http://html5.validator.nu/ Html5 Browser capability test (en) http://html5test.com/ Html readyness &#8211; fancy browser comparison (en) http://html5readiness.com/ Modernizr &#8211; Cross-Browser Html5 &#038; CSS3 Support (en) http://www.modernizr.com/ Html5Shiv &#8211; Html5 for IE (en) &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2010/11/27/html5-sammlung-von-ressourcen-dokus-und-browser-fallbacks/" class="more-link">Continue reading<span class="screen-reader-text"> "HTML5 &#8211; Sammlung von Ressourcen, Dokus und Browser-Fallbacks"</span></a></p>
The post <a href="https://nerdpress.org/2010/11/27/html5-sammlung-von-ressourcen-dokus-und-browser-fallbacks/">HTML5 – Sammlung von Ressourcen, Dokus und Browser-Fallbacks</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>Hier mal eine anfänglich kleine Sammlung zum Thema HTML 5 generell &#8211; grob kategorisiert. Vervollständigungen und Streichungen willkommen.</p>
<p><span id="more-1225"></span></p>
<h2>Cross Browser Helper</h2>
<h3>Html 5 Validator (en)</h3>
<p><a href="http://html5.validator.nu/">http://html5.validator.nu/</a></p>
<h3>Html5 Browser capability test (en)</h3>
<p><a href="http://html5test.com/">http://html5test.com/</a></p>
<h3>Html readyness &#8211; fancy browser comparison (en)</h3>
<p><a href="http://html5readiness.com/">http://html5readiness.com/</a></p>
<h3>Modernizr &#8211; Cross-Browser Html5 &#038; CSS3 Support (en)</h3>
<p><a href="http://www.modernizr.com/">http://www.modernizr.com/</a></p>
<h3>Html5Shiv &#8211; Html5 for IE (en)</h3>
<p><a href="http://code.google.com/p/html5shiv/">http://code.google.com/p/html5shiv/</a></p>
<h3>IE-7 js &#8211; Standard complient IE 7 (en)</h3>
<p><a href="http://code.google.com/p/ie7-js/">http://code.google.com/p/ie7-js/</a></p>
<h3>Html 5 CSS-Reset (en)</h3>
<p><a href="http://html5reset.org/ ">http://html5reset.org/ </a><br />
<a href="http://html5doctor.com/html-5-reset-stylesheet/">http://html5doctor.com/html-5-reset-stylesheet/</a></p>
<h3>HTML 5 Boilerplate &#8211; Best Practices, Scripts und Server-Konfigurationen</h3>
<p><a href="http://html5boilerplate.com/">http://html5boilerplate.com/</a> (en)<br />
<a href="http://de.html5boilerplate.com/">http://de.html5boilerplate.com/</a> (de)</p>
<h2>Audio/Video</h2>
<h3>Html 5 Audio and Video &#8211; What you must know (en)</h3>
<p><a href="http://net.tutsplus.com/tutorials/html-css-techniques/html5-audio-and-video-what-you-must-know/">http://net.tutsplus.com/tutorials/html-css-techniques/html5-audio-and-video-what-you-must-know/</a></p>
<h3>Video accessiblity (en)</h3>
<p>http://wearehugh.com/public/2010/08/html5-video-accessibility/<a href="http://wearehugh.com/public/2010/08/html5-video-accessibility/">Your text to link&#8230;</a></p>
<h2>Canvas</h2>
<h3>Reference Guide (de)</h3>
<p><a href="http://canvas.quaese.de/">http://canvas.quaese.de/</a></p>
<h3>Canvas beginners guides (en)</h3>
<p><a href="http://www.brighthub.com/internet/web-development/articles/38744.aspx">http://www.brighthub.com/internet/web-development/articles/38744.aspx</a><br />
<a href="http://www.visitmix.com/Articles/Translating-CANVAS-with-HTML5">http://www.visitmix.com/Articles/Translating-CANVAS-with-HTML5</a></p>
<h3>Canvas demos &#038; tutorials (en)</h3>
<p><a href="http://www.canvasdemos.com/">http://www.canvasdemos.com/</a></p>
<h2>Cookbooks &#038; Tutorials</h2>
<h3>Html 5 cheatsheet</h3>
<p><a href="http://websitesetup.org/html5-cheat-sheet/">http://websitesetup.org/html5-cheat-sheet/</a></p>
<h3>WHATWG Weblog (en)</h3>
<p><a href="http://blog.whatwg.org/">http://blog.whatwg.org/</a></p>
<h3>Html 5 laboratory (en)</h3>
<p><a href="http://www.html5laboratory.com/">http://www.html5laboratory.com/</a></p>
<h3>Dive into Html 5 (en)</h3>
<p><a href="http://diveintohtml5.org/">http://diveintohtml5.org/</a></p>
<h3>Html5 Playground (en)</h3>
<p><a href="http://www.html5rocks.com/">http://www.html5rocks.com/</a></p>
<h3>Tag reference (en)</h3>
<p><a href="http://www.w3schools.com/html5/html5_reference.asp">http://www.w3schools.com/html5/html5_reference.asp</a></p>
<h3>Fancy tag reference (en)</h3>
<p><a href="http://joshduck.com/periodic-table.html">http://joshduck.com/periodic-table.html</a></p>
<h3>Html5 Techniques &#8211; Ultimate collection of tutorials (en)</h3>
<p><a href="http://www.tutoriallounge.com/2010/11/html5-techniques-ultimate-collection-of-tutorials/">http://www.tutoriallounge.com/2010/11/html5-techniques-ultimate-collection-of-tutorials/</a></p>
<h3>Useful html 5 code snippets (en)</h3>
<p><a href="http://www.onextrapixel.com/2010/11/15/useful-html5-code-snippets-you-can-use-today/">http://www.onextrapixel.com/2010/11/15/useful-html5-code-snippets-you-can-use-today/</a></p>
<h3>Geolocation using the Google API (en)</h3>
<p><a href="http://papermashup.com/html5-geo-location-using-the-google-api/">http://papermashup.com/html5-geo-location-using-the-google-api/</a></p>
<h3>Fun with html5 forms</h3>
<p><a href="http://thinkvitamin.com/code/fun-with-html5-forms/">http://thinkvitamin.com/code/fun-with-html5-forms/</a></p>
<h2>Blog-Artikel &#038; andere Quellen</h2>
<h3>Webkrauts Artikel zum Thema (de)</h3>
<p><a href="http://www.webkrauts.de/category/html5-einfuehrung/">http://www.webkrauts.de/category/html5-einfuehrung/</a></p>
<h3>What beautiful Html5 code looks like (en)</h3>
<p><a href="http://css-tricks.com/what-beautiful-html-code-looks-like/">http://css-tricks.com/what-beautiful-html-code-looks-like/</a></p>
<h3>48 Flash killing HTML 5 demos (en)</h3>
<p><a href="http://www.hongkiat.com/blog/48-excellent-html5-demos/">http://www.hongkiat.com/blog/48-excellent-html5-demos/</a></p>
<h3>HTML 5 facts &#038; myths (en)</h3>
<p><a href="http://www.smashingmagazine.com/2010/09/23/html5-the-facts-and-the-myths/">http://www.smashingmagazine.com/2010/09/23/html5-the-facts-and-the-myths/</a></p>
<h3>Learning to love html 5 (en)</h3>
<p><a href="http://www.smashingmagazine.com/2010/11/10/learning-to-love-html5/">http://www.smashingmagazine.com/2010/11/10/learning-to-love-html5/</a></p>
<h3>Designing a html 5 layout from scratch (en)</h3>
<p><a href="http://www.smashingmagazine.com/2009/08/04/designing-a-html-5-layout-from-scratch/">http://www.smashingmagazine.com/2009/08/04/designing-a-html-5-layout-from-scratch/</a></p>The post <a href="https://nerdpress.org/2010/11/27/html5-sammlung-von-ressourcen-dokus-und-browser-fallbacks/">HTML5 – Sammlung von Ressourcen, Dokus und Browser-Fallbacks</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
					<wfw:commentRss>https://nerdpress.org/2010/11/27/html5-sammlung-von-ressourcen-dokus-und-browser-fallbacks/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Ajax (Fake) Push: Long Polling mit HTML 5 WebWorker</title>
		<link>https://nerdpress.org/2010/06/11/ajax-fake-push-long-polling-mit-html-5-dedicated-worker/</link>
					<comments>https://nerdpress.org/2010/06/11/ajax-fake-push-long-polling-mit-html-5-dedicated-worker/#comments</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Fri, 11 Jun 2010 11:28:23 +0000</pubDate>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Comet]]></category>
		<category><![CDATA[Html5]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Long Poll]]></category>
		<category><![CDATA[Push]]></category>
		<category><![CDATA[Threads]]></category>
		<category><![CDATA[WebWorker]]></category>
		<category><![CDATA[Worker]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=1037</guid>

					<description><![CDATA[<p>Push-Mechanismen im Web sind mittlerweile weit verbreitet &#8211; die Anforderungen an die Infrastruktur aber recht hoch. Nichts geht ohne Plugins (Flash, Applet, WebSocket) &#8211; dann braucht man mindestens einen zweiten Server, der via persistenter Verbindung Nachrichten verteilt. Bedient man sich herkömmlicher JavaScript-Technik, muss man mit aynchronen Ajax-Requests herumkaspern, sich mit Timeouts, Memory-Leaks und Cross-Domain-Sicherheitspolicen herumschlagen. &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2010/06/11/ajax-fake-push-long-polling-mit-html-5-dedicated-worker/" class="more-link">Continue reading<span class="screen-reader-text"> "Ajax (Fake) Push: Long Polling mit HTML 5 WebWorker"</span></a></p>
The post <a href="https://nerdpress.org/2010/06/11/ajax-fake-push-long-polling-mit-html-5-dedicated-worker/">Ajax (Fake) Push: Long Polling mit HTML 5 WebWorker</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>Push-Mechanismen im Web sind mittlerweile weit verbreitet &#8211; die Anforderungen an die Infrastruktur aber recht hoch. Nichts geht ohne Plugins (Flash, Applet, WebSocket) &#8211; dann braucht man mindestens einen zweiten Server, der via persistenter Verbindung Nachrichten verteilt. </p>
<p><span id="more-1037"></span></p>
<p>Bedient man sich herkömmlicher JavaScript-Technik, muss man mit aynchronen Ajax-Requests herumkaspern, sich mit Timeouts, Memory-Leaks und Cross-Domain-Sicherheitspolicen herumschlagen. Und auch hier kommt man nicht herum, den Server zu tweaken oder gleich einen zweiten aufzusetzen, der ausschließlich auf Polls oder Long-Polls trainiert ist.</p>
<p>Gerade in der PHP-Welt ist es nicht einfach, einen üblichen LAMP-Stack soweit zu bringen, dass so etwas auch unter Last funktioniert &#8211; Java ist da wie immer weiter und bietet mit <a href="http://java.sun.com/products/jms/">JMS</a> ein einheitliches Interface &#8211; da gibt es Software für den gewöhnlichen Servletcontainer, im Anwendungsserver muss das laut Spezifikation sogar im Lieferumfang enthalten sein.</p>
<p>Möchte man trotzdem mit &#8220;Bordmitteln&#8221; mal schnell eine Chatbox aufsetzen, führt Longpolling + Ajax eigentlich schnell zu einem akzeptablen Ergebnis &#8211; nichts für Millionen konkurrierende Zugriffe, aber immerhin eine nette Spielerei für zwischendurch. Wäre da nicht ständiges Warten auf die Response, das sich nach einiger Zeit einerseits mit einer merklichen Ruckelorgie bemerkbar macht oder gar den Mauszeiger in eine ewiglich drehende Sanduhr verwandelt.</p>
<h4>HTML 5 to the rescue&#8230;</h4>
<p>HTML 5 kann sogenannte Dedicated Worker &#8211; &#8220;echte&#8221; Workerthreads auf Betriebssystemebene, die man mit einer Zeile spawnen kann.</p>
<pre class="brush: jscript; title: ; notranslate">
new Worker('meinScript.js')
</pre>
<p>Innerhalb eines Threads kann man lang laufende Rechenoperationen im Hintergrund verstecken &#8211; warum also nicht auch einen Ajax-Request? Allerdings haben diese Threads einen Nachteil: Aus Sicherheitsgründen laufen sie in einem klar abgegrenzten Scope, in dem sozusagen nichts vorhanden ist. Auch keine Referenz auf das document-Object der Elternseite. Das stoppt die meisten Javascript-Bibliotheken, wie bspw. JQuery. Man muss sich also mit Bordmitteln begnügen.</p>
<p>Eine Methode, die einen Worker initialisiert, könnte so aussehen:</p>
<pre class="brush: jscript; title: ; notranslate">
    _initializeLongPoll: function()
    {
      var messenger = this;

      var worker = new Worker('my-ajax-worker.js');
        worker.onmessage = function(event)
        {
          var json = jQuery.parseJSON(event.data);
            
          // NEUE CHAT-NACHRICHT ERZEUGEN
          messenger.$_list.append($('&lt;li class=&quot;messenger-list-item&quot;&gt;'
            + '&lt;strong class=&quot;messenger-list-item-author&quot;&gt;' + json.author + '&lt;/strong&gt;'
            + '&lt;span class=&quot;messenger-list-item-message&quot;&gt;' + json.text + '&lt;/span&gt;&lt;/li&gt;'));
        };
    }
</pre>
<p>&#8220;my-ajax-worker.js&#8221; ist ausschließlich für den Ajax-Request zuständig. Hier wird ein dynamisches Javascript in einem Symfony-Projekt generiert:</p>
<pre class="brush: jscript; title: ; notranslate">
    
    var onLoad = function()
    {
      var output = httpRequest.responseText;
      if (output) {
       
        // DELEGIERT DIE RESPONSE ZURÜCK.
        postMessage(output.trim());
        
        // ERZEUGE NEUEN XmlHttpRequest
        httpRequest = initRequest();
      }
    };

    // WIR SPAREN UND DEN X-BROWSER XmlHttpRequest-KRAM
    var httpRequest = initRequest();
</pre>
<p>Details zum serverseitigen Script möchte ich an dieser Stelle vernachlässigen, im Grunde funktioniert es folgendermaßen: Es arbeitet so lange, bis eine Änderung festzustellen ist. Erst bei Änderung wird die Response an den Client ausgeliefert (darum heißt es &#8220;Long-Polling&#8221;, weil ein Request ganz schön lange dauern kann):</p>
<pre class="brush: java; title: ; notranslate">
while(true)
{
  if(newData())
  {
    return getNewData()
  }
  sleep(5);
}
</pre>
<p>Der Kram funktioniert natürlich nur in HTML5-Browsern, die das Worker-Objekt unterstützen. Dazu zählen Firefox 3.6, Google Chrome und natürlich Safari. Ob Opera es beherrscht, weiß ich nicht, ob der IE 8 es beherrscht, bezweifle ich. Aber wie gesagt: Es ist nur eine Spielerei und keine produktiv geeignete Anwendung. Demnächst schau ich mir auch mal die WebSocket API an&#8230;</p>
<h4>Known Issues</h4>
<p>Vorsicht mit <a href="http://php.net/manual/de/function.session-start.php">session_start()</a> und konkurrierenden (asynchronen) HTTP-Zugriffen. Im User-Sessionscope wird der Apache immer auf das Schließen einer Session warten, bis er dem nächsten Request erlaubt, die Session wieder &#8220;aufzunehmen&#8221;. Und im Normalfall dauert eine User-Session genau so lange wie die Request-Lifetime. Das führt dazu, dass bei 4 gleichzeitig abgefeuerten XmlHttpRequests diese trotzdem als Stack nach dem FIFO-Prinzip abgehandelt werden. Man verliert somit den Vorteil der Asynchronität. Es ist also zwingend erforderlich, die Session bereits vor dem Long-Poll-Loop abzuschließen (durch den Aufruf von <a href="http://php.net/manual/en/function.session-write-close.php">session_write_close()</a>;</p>The post <a href="https://nerdpress.org/2010/06/11/ajax-fake-push-long-polling-mit-html-5-dedicated-worker/">Ajax (Fake) Push: Long Polling mit HTML 5 WebWorker</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
					<wfw:commentRss>https://nerdpress.org/2010/06/11/ajax-fake-push-long-polling-mit-html-5-dedicated-worker/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Next Level Javascript Error Tracking</title>
		<link>https://nerdpress.org/2010/04/10/next-level-javascript-error-tracking/</link>
					<comments>https://nerdpress.org/2010/04/10/next-level-javascript-error-tracking/#comments</comments>
		
		<dc:creator><![CDATA[Max Girkens]]></dc:creator>
		<pubDate>Sat, 10 Apr 2010 12:11:03 +0000</pubDate>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Error]]></category>
		<category><![CDATA[Exceptionhub]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Tracking]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=914</guid>

					<description><![CDATA[<p>Exceptionhub protokolliert clientseitig auftretende Javascript Fehler. * Logs all JavaScript errors (local or remote) * Provides a stack trace to find the cause in all browsers * Groups errors by cause * Development and Production modes * RSS feeds for errors Einfach einbinden via Javascript im Seitenheader. Dann kriegt man schöne Statistiken über Javascript Fehler &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2010/04/10/next-level-javascript-error-tracking/" class="more-link">Continue reading<span class="screen-reader-text"> "Next Level Javascript Error Tracking"</span></a></p>
The post <a href="https://nerdpress.org/2010/04/10/next-level-javascript-error-tracking/">Next Level Javascript Error Tracking</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p><a href="http://www.exceptionhub.com/">Exceptionhub</a> protokolliert clientseitig auftretende Javascript Fehler.</p>
<blockquote><p>
    *  Logs all JavaScript errors (local or remote)<br />
    * Provides a stack trace to find the cause in all browsers<br />
    * Groups errors by cause<br />
    * Development and Production modes<br />
    * RSS feeds for errors
</p></blockquote>
<p>Einfach einbinden via Javascript im Seitenheader. Dann kriegt man schöne Statistiken über Javascript Fehler mit Browser und OS Infos, Mail-Notifications usw.<br />
<span id="more-914"></span><br />
Ein bißchen wie Google Analytics.</p>
<p>Das ganze ist (noch) kostenlos während der betaPhase.</p>
<p>Auf die Idee clientseitige Fehler via Ajax auf dem Server zu loggen, wäre ich irgendwie garnicht gekommen. <a href="http://www.the-art-of-web.com/javascript/ajax-onerror/">Andere</a> <a href="http://www.codeproject.com/kb/Ajax/LogClientSideJSErrors2Srv.aspx">Leute schon</a>.<br />
Trotzdem wundert es mich in Nachhinein fast dass es da nichts verbreiteteres gibt.<br />
Das schreit ja eigentlich nach einem Symfony Plugin, oder?</p>
<p>:)</p>The post <a href="https://nerdpress.org/2010/04/10/next-level-javascript-error-tracking/">Next Level Javascript Error Tracking</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
					<wfw:commentRss>https://nerdpress.org/2010/04/10/next-level-javascript-error-tracking/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
	</channel>
</rss>
