SlideShare ist ein Scribd-Unternehmen logo
1 von 13
Einführung RequireJS Legacy-Code
RequireJS im Einsatz
Andreas Wolf
SYN Systems GmbH
9. Juni 2013
RequireJS im Einsatz Andreas Wolf, SYN Systems GmbH
Inspiring people to
share
Einführung RequireJS Legacy-Code
Inhalt
Einführung
RequireJS
Legacy-Code
RequireJS im Einsatz Andreas Wolf, SYN Systems GmbH
Inspiring people to
share
Einführung RequireJS Legacy-Code
$ whois referent
Andreas Wolf
aw@syn-systems.com
Jabber: awolf@jabber.ccc.de
Twitter: @andreaswo
aus Karlsruhe, Baden(-Württemberg)
TYPO3-User seit 2003
Mitglied im TYPO3-Core-Team seit März 2011
RequireJS-User seit irgendwann 2012
RequireJS im Einsatz Andreas Wolf, SYN Systems GmbH
Inspiring people to
share
Einführung RequireJS Legacy-Code
Motivation
In traditionellem JS-Code:
Abhängigkeiten verwalten ist schwer
Nachladen ist kompliziert (script-Tags manuell in DOM einhängen)
globaler Namensraum verschmutzt schnell
nur eine Version einer Bibliothek gleichzeitig ladbar
RequireJS im Einsatz Andreas Wolf, SYN Systems GmbH
Inspiring people to
share
Einführung RequireJS Legacy-Code
Was ist RequireJS?
RequireJS is a JavaScript le and module loader. It is
optimized for in-browser use, [. . . ]. Using a modular script
loader like RequireJS will improve the speed and quality of
your code.
(von requirejs.org)
RequireJS im Einsatz Andreas Wolf, SYN Systems GmbH
Inspiring people to
share
Einführung RequireJS Legacy-Code
RequireJS
implementiert AMD-Standard (Asynchronous Module De nition)
lädt Module, löst dabei Abhängigkeiten auf
kann auch Legacy-Code verwendbar machen
kommt meistens mit maximal zwei script-Tags aus
RequireJS im Einsatz Andreas Wolf, SYN Systems GmbH
Inspiring people to
share
Einführung RequireJS Legacy-Code
Einfaches Beispiel
De nieren (Library/Modulname.js):
1 define('Library/Modulname', ['dependency1', 'dependency2
'], function() {
2 // Here be dragons
3 });
Einbinden (Main.js):
1 require(['Library/Modulname'], function(Modul) {
2 // More dragons here
3 });
RequireJS im Einsatz Andreas Wolf, SYN Systems GmbH
Inspiring people to
share
Einführung RequireJS Legacy-Code
Kon guration
1 require.config({
2 paths: {
3 "flot": 'Vendor/flot/jquery.flot'
4 },
5 shim: {
6 "flot": {
7 deps: 'jquery'
8 }
9 }
10 });
RequireJS im Einsatz Andreas Wolf, SYN Systems GmbH
Inspiring people to
share
Einführung RequireJS Legacy-Code
Modulde nition
1 <head>
2 ...
3 <script type="text/javascript" src="require-config.js"
></script>
4 <script type="text/javascript" src="require-2.1.6.js"
data-main="main.js"></script>
5 </head>
RequireJS im Einsatz Andreas Wolf, SYN Systems GmbH
Inspiring people to
share
Einführung RequireJS Legacy-Code
Nutzen von Dependencies
1 require(['MeinModul', 'jquery'], function(Modul, $) {
2 $('a').click(function() {
3 alert("Link geklickt!");
4 });
5
6 Modul.meineFunktion();
7 });
RequireJS im Einsatz Andreas Wolf, SYN Systems GmbH
Inspiring people to
share
Einführung RequireJS Legacy-Code
Umgehen mit Legacy-Code
nicht jedes Modul benutzt de ne()
die Lösung: "shim"
shim ermöglicht
RequireJS kapselt Module, die in globalen Namensraum schreiben
(siehe shim[<modulname>]['exports'])
RequireJS im Einsatz Andreas Wolf, SYN Systems GmbH
Inspiring people to
share
Einführung RequireJS Legacy-Code
Fragen? Diskussion?
?RequireJS im Einsatz Andreas Wolf, SYN Systems GmbH
Inspiring people to
share
Inspiring people to share.

Weitere ähnliche Inhalte

Ähnlich wie Einführung in RequireJS

Startimpuls at Microsoft w/ IFJ
Startimpuls at Microsoft w/ IFJStartimpuls at Microsoft w/ IFJ
Startimpuls at Microsoft w/ IFJReto Laemmler
 
Backend-Services mit Rust
Backend-Services mit RustBackend-Services mit Rust
Backend-Services mit RustJens Siebert
 
Docker-Images mit vorinstallierter Instanz einer Oracle-DB
Docker-Images mit vorinstallierter Instanz einer Oracle-DBDocker-Images mit vorinstallierter Instanz einer Oracle-DB
Docker-Images mit vorinstallierter Instanz einer Oracle-DBPeter Ramm
 
Gradle - Beginner's Workshop (german)
Gradle - Beginner's Workshop (german)Gradle - Beginner's Workshop (german)
Gradle - Beginner's Workshop (german)Joachim Baumann
 
Production-ready Infrastruktur in 3 Wochen
Production-ready Infrastruktur in 3 WochenProduction-ready Infrastruktur in 3 Wochen
Production-ready Infrastruktur in 3 WochenAndré Goliath
 
Kuck mal, Node.js! Einstieg für .NET Entwickler mit Visual Studio Code und Ty...
Kuck mal, Node.js! Einstieg für .NET Entwickler mit Visual Studio Code und Ty...Kuck mal, Node.js! Einstieg für .NET Entwickler mit Visual Studio Code und Ty...
Kuck mal, Node.js! Einstieg für .NET Entwickler mit Visual Studio Code und Ty...Gregor Biswanger
 
Domain Driven Design in Rails
Domain Driven Design in RailsDomain Driven Design in Rails
Domain Driven Design in RailsAngelo Maron
 
Cloud Provisioning mit Juju
Cloud Provisioning mit JujuCloud Provisioning mit Juju
Cloud Provisioning mit JujuFrank Müller
 
elemente websolutions - Zusammenfassung T3DD09
elemente websolutions - Zusammenfassung T3DD09elemente websolutions - Zusammenfassung T3DD09
elemente websolutions - Zusammenfassung T3DD09elemente websolutions
 
stackconf 2020 | SecDevOps in der Cloud by Florian Wiethoff
stackconf 2020 | SecDevOps in der Cloud by Florian Wiethoffstackconf 2020 | SecDevOps in der Cloud by Florian Wiethoff
stackconf 2020 | SecDevOps in der Cloud by Florian WiethoffNETWAYS
 
Schnelle Winkel: 10x schnellere Webapps mit AngularJS und JEE
Schnelle Winkel: 10x schnellere Webapps mit AngularJS und JEESchnelle Winkel: 10x schnellere Webapps mit AngularJS und JEE
Schnelle Winkel: 10x schnellere Webapps mit AngularJS und JEEBenjamin Schmid
 
Dnug35 ak-dev.071111-beyond
Dnug35 ak-dev.071111-beyondDnug35 ak-dev.071111-beyond
Dnug35 ak-dev.071111-beyondUlrich Krause
 
Architectures for .Net Core Applications
Architectures for .Net Core ApplicationsArchitectures for .Net Core Applications
Architectures for .Net Core ApplicationsRobin Sedlaczek
 
Die nächsten 100 Microservices
Die nächsten 100 MicroservicesDie nächsten 100 Microservices
Die nächsten 100 MicroservicesQAware GmbH
 
Das Runde muss in das Eckige - Java-Anwendungen für Kubernetes entwickeln und...
Das Runde muss in das Eckige - Java-Anwendungen für Kubernetes entwickeln und...Das Runde muss in das Eckige - Java-Anwendungen für Kubernetes entwickeln und...
Das Runde muss in das Eckige - Java-Anwendungen für Kubernetes entwickeln und...gedoplan
 
Meine ersten 12 Monate als Plugin-Entwickler für WordPress - WP Camp 2012 Berlin
Meine ersten 12 Monate als Plugin-Entwickler für WordPress - WP Camp 2012 BerlinMeine ersten 12 Monate als Plugin-Entwickler für WordPress - WP Camp 2012 Berlin
Meine ersten 12 Monate als Plugin-Entwickler für WordPress - WP Camp 2012 BerlinDavid Decker
 
Cloud Architekturen - von "less Server" zu Serverless
Cloud Architekturen - von "less Server" zu ServerlessCloud Architekturen - von "less Server" zu Serverless
Cloud Architekturen - von "less Server" zu ServerlessOPEN KNOWLEDGE GmbH
 
Schnell, schneller, Quarkus!!
Schnell, schneller, Quarkus!!Schnell, schneller, Quarkus!!
Schnell, schneller, Quarkus!!gedoplan
 
Steinzeit war gestern! Wege der Cloud-nativen Evolution.
Steinzeit war gestern! Wege der Cloud-nativen Evolution.Steinzeit war gestern! Wege der Cloud-nativen Evolution.
Steinzeit war gestern! Wege der Cloud-nativen Evolution.QAware GmbH
 
MicroProfile-Anwendungen mit Quarkus
MicroProfile-Anwendungen mit QuarkusMicroProfile-Anwendungen mit Quarkus
MicroProfile-Anwendungen mit Quarkusgedoplan
 

Ähnlich wie Einführung in RequireJS (20)

Startimpuls at Microsoft w/ IFJ
Startimpuls at Microsoft w/ IFJStartimpuls at Microsoft w/ IFJ
Startimpuls at Microsoft w/ IFJ
 
Backend-Services mit Rust
Backend-Services mit RustBackend-Services mit Rust
Backend-Services mit Rust
 
Docker-Images mit vorinstallierter Instanz einer Oracle-DB
Docker-Images mit vorinstallierter Instanz einer Oracle-DBDocker-Images mit vorinstallierter Instanz einer Oracle-DB
Docker-Images mit vorinstallierter Instanz einer Oracle-DB
 
Gradle - Beginner's Workshop (german)
Gradle - Beginner's Workshop (german)Gradle - Beginner's Workshop (german)
Gradle - Beginner's Workshop (german)
 
Production-ready Infrastruktur in 3 Wochen
Production-ready Infrastruktur in 3 WochenProduction-ready Infrastruktur in 3 Wochen
Production-ready Infrastruktur in 3 Wochen
 
Kuck mal, Node.js! Einstieg für .NET Entwickler mit Visual Studio Code und Ty...
Kuck mal, Node.js! Einstieg für .NET Entwickler mit Visual Studio Code und Ty...Kuck mal, Node.js! Einstieg für .NET Entwickler mit Visual Studio Code und Ty...
Kuck mal, Node.js! Einstieg für .NET Entwickler mit Visual Studio Code und Ty...
 
Domain Driven Design in Rails
Domain Driven Design in RailsDomain Driven Design in Rails
Domain Driven Design in Rails
 
Cloud Provisioning mit Juju
Cloud Provisioning mit JujuCloud Provisioning mit Juju
Cloud Provisioning mit Juju
 
elemente websolutions - Zusammenfassung T3DD09
elemente websolutions - Zusammenfassung T3DD09elemente websolutions - Zusammenfassung T3DD09
elemente websolutions - Zusammenfassung T3DD09
 
stackconf 2020 | SecDevOps in der Cloud by Florian Wiethoff
stackconf 2020 | SecDevOps in der Cloud by Florian Wiethoffstackconf 2020 | SecDevOps in der Cloud by Florian Wiethoff
stackconf 2020 | SecDevOps in der Cloud by Florian Wiethoff
 
Schnelle Winkel: 10x schnellere Webapps mit AngularJS und JEE
Schnelle Winkel: 10x schnellere Webapps mit AngularJS und JEESchnelle Winkel: 10x schnellere Webapps mit AngularJS und JEE
Schnelle Winkel: 10x schnellere Webapps mit AngularJS und JEE
 
Dnug35 ak-dev.071111-beyond
Dnug35 ak-dev.071111-beyondDnug35 ak-dev.071111-beyond
Dnug35 ak-dev.071111-beyond
 
Architectures for .Net Core Applications
Architectures for .Net Core ApplicationsArchitectures for .Net Core Applications
Architectures for .Net Core Applications
 
Die nächsten 100 Microservices
Die nächsten 100 MicroservicesDie nächsten 100 Microservices
Die nächsten 100 Microservices
 
Das Runde muss in das Eckige - Java-Anwendungen für Kubernetes entwickeln und...
Das Runde muss in das Eckige - Java-Anwendungen für Kubernetes entwickeln und...Das Runde muss in das Eckige - Java-Anwendungen für Kubernetes entwickeln und...
Das Runde muss in das Eckige - Java-Anwendungen für Kubernetes entwickeln und...
 
Meine ersten 12 Monate als Plugin-Entwickler für WordPress - WP Camp 2012 Berlin
Meine ersten 12 Monate als Plugin-Entwickler für WordPress - WP Camp 2012 BerlinMeine ersten 12 Monate als Plugin-Entwickler für WordPress - WP Camp 2012 Berlin
Meine ersten 12 Monate als Plugin-Entwickler für WordPress - WP Camp 2012 Berlin
 
Cloud Architekturen - von "less Server" zu Serverless
Cloud Architekturen - von "less Server" zu ServerlessCloud Architekturen - von "less Server" zu Serverless
Cloud Architekturen - von "less Server" zu Serverless
 
Schnell, schneller, Quarkus!!
Schnell, schneller, Quarkus!!Schnell, schneller, Quarkus!!
Schnell, schneller, Quarkus!!
 
Steinzeit war gestern! Wege der Cloud-nativen Evolution.
Steinzeit war gestern! Wege der Cloud-nativen Evolution.Steinzeit war gestern! Wege der Cloud-nativen Evolution.
Steinzeit war gestern! Wege der Cloud-nativen Evolution.
 
MicroProfile-Anwendungen mit Quarkus
MicroProfile-Anwendungen mit QuarkusMicroProfile-Anwendungen mit Quarkus
MicroProfile-Anwendungen mit Quarkus
 

Einführung in RequireJS

  • 1. Einführung RequireJS Legacy-Code RequireJS im Einsatz Andreas Wolf SYN Systems GmbH 9. Juni 2013 RequireJS im Einsatz Andreas Wolf, SYN Systems GmbH Inspiring people to share
  • 2. Einführung RequireJS Legacy-Code Inhalt Einführung RequireJS Legacy-Code RequireJS im Einsatz Andreas Wolf, SYN Systems GmbH Inspiring people to share
  • 3. Einführung RequireJS Legacy-Code $ whois referent Andreas Wolf aw@syn-systems.com Jabber: awolf@jabber.ccc.de Twitter: @andreaswo aus Karlsruhe, Baden(-Württemberg) TYPO3-User seit 2003 Mitglied im TYPO3-Core-Team seit März 2011 RequireJS-User seit irgendwann 2012 RequireJS im Einsatz Andreas Wolf, SYN Systems GmbH Inspiring people to share
  • 4. Einführung RequireJS Legacy-Code Motivation In traditionellem JS-Code: Abhängigkeiten verwalten ist schwer Nachladen ist kompliziert (script-Tags manuell in DOM einhängen) globaler Namensraum verschmutzt schnell nur eine Version einer Bibliothek gleichzeitig ladbar RequireJS im Einsatz Andreas Wolf, SYN Systems GmbH Inspiring people to share
  • 5. Einführung RequireJS Legacy-Code Was ist RequireJS? RequireJS is a JavaScript le and module loader. It is optimized for in-browser use, [. . . ]. Using a modular script loader like RequireJS will improve the speed and quality of your code. (von requirejs.org) RequireJS im Einsatz Andreas Wolf, SYN Systems GmbH Inspiring people to share
  • 6. Einführung RequireJS Legacy-Code RequireJS implementiert AMD-Standard (Asynchronous Module De nition) lädt Module, löst dabei Abhängigkeiten auf kann auch Legacy-Code verwendbar machen kommt meistens mit maximal zwei script-Tags aus RequireJS im Einsatz Andreas Wolf, SYN Systems GmbH Inspiring people to share
  • 7. Einführung RequireJS Legacy-Code Einfaches Beispiel De nieren (Library/Modulname.js): 1 define('Library/Modulname', ['dependency1', 'dependency2 '], function() { 2 // Here be dragons 3 }); Einbinden (Main.js): 1 require(['Library/Modulname'], function(Modul) { 2 // More dragons here 3 }); RequireJS im Einsatz Andreas Wolf, SYN Systems GmbH Inspiring people to share
  • 8. Einführung RequireJS Legacy-Code Kon guration 1 require.config({ 2 paths: { 3 "flot": 'Vendor/flot/jquery.flot' 4 }, 5 shim: { 6 "flot": { 7 deps: 'jquery' 8 } 9 } 10 }); RequireJS im Einsatz Andreas Wolf, SYN Systems GmbH Inspiring people to share
  • 9. Einführung RequireJS Legacy-Code Modulde nition 1 <head> 2 ... 3 <script type="text/javascript" src="require-config.js" ></script> 4 <script type="text/javascript" src="require-2.1.6.js" data-main="main.js"></script> 5 </head> RequireJS im Einsatz Andreas Wolf, SYN Systems GmbH Inspiring people to share
  • 10. Einführung RequireJS Legacy-Code Nutzen von Dependencies 1 require(['MeinModul', 'jquery'], function(Modul, $) { 2 $('a').click(function() { 3 alert("Link geklickt!"); 4 }); 5 6 Modul.meineFunktion(); 7 }); RequireJS im Einsatz Andreas Wolf, SYN Systems GmbH Inspiring people to share
  • 11. Einführung RequireJS Legacy-Code Umgehen mit Legacy-Code nicht jedes Modul benutzt de ne() die Lösung: "shim" shim ermöglicht RequireJS kapselt Module, die in globalen Namensraum schreiben (siehe shim[<modulname>]['exports']) RequireJS im Einsatz Andreas Wolf, SYN Systems GmbH Inspiring people to share
  • 12. Einführung RequireJS Legacy-Code Fragen? Diskussion? ?RequireJS im Einsatz Andreas Wolf, SYN Systems GmbH Inspiring people to share