I showed the beta website to a friend. I said it should be fast. He replied: fast is an understatement. It’s instant.
That’s the good. Now… the bad.
The realization has come that the Svelte community is still growing and many problems are still pretty much unsolved.
Sapper is a super cool project with really good ideas but it’s not that actively being worked on.
The Routify project that I am involved in is evolving at a rapid pace, but it’s nowhere near the maturity that projects like Gatsby or GridSome have.
If my overall goal is to just have a great website, shouldn’t we just use a more mature technology?
One that has validated and tested server side rendering – hydration – code splitting – all the goodies that you need to deliver the quality I want?
The speed benefit of Svelte is obvious, but won’t we have a similar speed if we use React or Vue.js? The speed benefit might simply be in the fact that it’s an SPA, and not in Svelte itself.
If you look at a project like Gatbsy, they have templates like a starter blog. On the Vue.js site there is GridSome (nice website!).
There’s probably many resources to be found and every conceivable problem you run into, somebody has run in before. For example, a current problem I have now is that the Open Graph meta tags (which are used when sharing links on social media) are controlled through the Javascript, whereas they should be in the static HTML to be picked up by LinkedIn, Twitter and the likes.
On our site we like to have different Open Graph preview images depending on which section of the site you link to. If you have control over the HTML output, that is very easy to do. But if everything redirects to index.html, what do you do now?
The answer is something with SSR, but I don’t know how to implement that myself. I have to depend on my router to do it.
This seems to be a solved problem in the GridSome and Gatsby communities as far as I can tell. I would like to hear from someone experienced if that is actually the case or it’s more like a not really.
Nobody has solved this in the Svelte community as far as I know. This is a problem that could prevent me from shipping the website in the end. It’s not the end of the world but quality problems can pile up.
I guess at some level, everything is a balance act, and who cares about perfect Open Graph tags when you have a faster site? Do you really need something like a sitemap.xml – and a perfect indexable site (actually… yes.)? Which website building techniques from the past — including SEO techniques — are still relevant?
It’s easy to shove the learnings from the past under a rug and ship a new cool website. But what if what you ship is just objectively worse? I read about the problems with SPAs and accessibility I’m almost thinking to just shut down this experiment completely and go for a fully static website.
What’s the point of fast loading if in the process you are making your content inaccessible to part of your audience? That’s just stupid and wildly irresponsible.
(BTW, I see there’s something like Gatsby cloud – I can’t help but wonder why you need a service to deploy a simple website? Did we really all collectively forget how to FTP and SSH?)
So let’s say that doubts are creeping up about whether this is the way to go.
Now, on the other hand. I have invested in learning Svelte. Our codebase is running Svelte. The other frameworks don’t have the same animation capabilities that I plan to use. I would hate to have to write code that looks like the examples here.
So… I think for now I am just going to push through and try to solve as many problems as possible. But there’s a business reality. There’s a set amount of time tp work on our website before we have to move back to client work. If we can’t make something better (technically), we’ll have to shut down the experiment.
Maybe we’ll just provide a content update on our portfolio, ship the CSS improvements we made and call it a day. I don’t know.
We might run a beta of our website in parallel with the real website and be transparent about the problems with it. There’s clear talk about these problems in the industry. Maybe a combination of our work and better tools will solve the needs that we have in time.
But for now, I really don’t know. I am learning a ton though. So that’s good.
I had to wait for 2 hours in a hospital today, so naturally I spend my time writing down long-winded thoughts in Notes.app.We are re-building our company website in Svelte. This seemed to spark some interest on Twitter, so I decided to write about it.
This is a draft for a blog post that will appear on https://mono.company/ . This is the long and wieldy version that needs an edit, but that some might appreciate. It’s about some technical beginnings, it contains some thoughts on routers, and then goes into thoughts about code splitting and ideas about how we could maybe replace WordPress(but probably won’t).
Replacing WordPress with Svelte: why bother?
We’ve recently started experimenting with using Svelte for our website. In this blog post, I’ll talk about some first findings and thoughts.
First of all, why?
To experiment with new technology
To make us excited about working on our site again
To have a codebase we can be proud of
To not have to fight WordPress’s caching mechanisms anymore
To not have to fight trying to make a WordPress site fast
Because we feel we are a bit stuck with our current site when it comes to experimenting with different ways to show our work
It’s an SPA!
First of all, what we are building is is essentially an SPA (Single Page Application).
This method of building a website comes with a different workflow than other methods of building websites, from static site generators to using CMSes like WordPress.
I am used to building sites with CMS’es; for years I experimented with static site generators like Jekyll; but I have never really built a site as an SPA. Up until I have always dismissed the idea, because I felt like there were too many disadvantages to shipping a site through a JS-only bundle. But a-hem -the times are changing – and I feel like I have to get on with the times. Which I might later regret.
SPAs essentially render all of your site’s content through Javascript. The biggest benefit is that an SPA does not need a page refresh. Clicking on navigation items or doing something on the page simply changes the content of the page, not the actual page you are on itself. The URL in the browser might change, but essentially every request you are visiting the same index.html. The requested URL is saved and passed into the router.
The biggest advantage here is speed. An SPA can be very fast. Once the initial bundle is loaded, you can navigate through it without any delays. We can see this in the test version of our site. It is fast. Really fast. And that makes me happy.
Let’s talk about routing first.
Routing
When you visit a web page, the page has a URL. The URL lets the browser know which page you are requesting. In an SPA you redirect every URL to index.html. In index.html, you then “catch” the URL that was requested (e.g. /work) and do something with it: typically render a page.
Routing can be very simple. You can theoretically write a router in 50-60 lines of Javascript (example; I did not write this code, but the fantastic pngwn did)
But a good router has more features than just simply displaying a page. For the Mono website, we chose to use Routify.
Routify is a file-based router. By constructing pages and paths you are essentially constructing routes that the router can derive. For me this is a super logical way to work as opposed to manually defining routes in a JS file.
If you’ve heard about Svelte, you might heard about Sapper. It works in similar ways.
A note on the Svelte ecosystem
It has to be said that Routify is quite new as a project. I am actively involved in this project to improve it myself. The authors are doing the hard work at the moment to create the best router for Svelte 3.
I see my role as promoting the router, explaining how to use it, providing good documentation, QA and being the “voice of the user”. The stated goal is that as a tool, Routify is so easy to that a beginner web developer could work with it and get things done.
Now, this is a good example of the state of the Svelte ecosystem. It’s young, there’s many things happening, but not a lot of it is locked down. This means that not every problem is solved yet, and some things might require some digging. That might not be up to your taste.
Bundle size
Earlier I mentioned that once the initial bundle is loaded, you can navigate through an SPA without any delay. This brings us to the topic of bundle size.
If your whole website is contained in a JS file, are you not loading a lot of things upfront that you don’t need? If your website has 30 pages and the visitor only visits 2 of them, aren’t you loading things that the visitor doesn’t need? What if they have a slow connection? Wouldn’t loading the code necessary to load 30 pages lead to a long initial render time?
All of the above are the kind of concerns you could have and that you need to be aware of when building SPAs. If your router supports code splitting (like Sapper does) you can migitate most bundle size problems (extended discussion here).
Code splitting is a technique to split your application into different pieces that are loaded on request. For section A you need bundle 1, for section B you need bundle 2, etc.
(Please note that this is how I understand it now – the whole notion of code splitting is pretty new to me).
Now, what about dynamic content?
If we take the example of blog posts, you could load dynamic content over an API and insert it in the page in a dynamic manner.
It makes no sense to make content part of your bundle. For example, we have about 95 blog posts on our web site. We can’t just add this content to our Javascript bundle. The simple act of bundling up, let’s say 15kb of HTML per post would lead to a bundle size of +-1.4Mb. What if the visitor never even visits the journal section of the site?
Having to request content dynamically comes with speed concerns. How and when do you build the page? Where does the content come from? How do we do this?
There are lots of solutions. To do things properly comes with new challenges. I think I am going to sidestep the “build a dynamic blog” problem for now and focus on rebuilding the website in a great way in Svelte except for the blog.
I’ll explain my rationale below.
The best of both worlds?
Our current site runs on WordPress.
Let’s consider the WordPress editing interface for a moment. I like having access to drafts, the multi user editing, the fact that I can easily add code blocks or callouts if I want to. I like that when I upload an image, WordPress automatically generates responsive images from the source, directly on the server. I can hit the publish button and have a post on my website in an instant, with a shareable URL.
Since we are rebuilding out website, it is now tempting to also rebuild the blog in Svelte. But there are a few technical realities.
First of all, the ecosystem around blogging with Svelte is not mature. There is no good sample Svelte blog project. There are no Svelte CMSes. You would essentially have to do the parts that you need from WordPress, from scratch.
There’s so many parts of WordPress that we actively use. We use categories, there is an RSS feed, there’s pagination; URL fallbacks; and that’s just scratching the surface.
And now I’m just describing the generated output side (i.e. what the CMS outputs). Then we have not even considered the user experience of writing and publishing. I’ve learned to love Gutenberg and for me there is no way back.
If we were to try and build the blog in Svelte, and try to “work with the least amount of technology possible” we would probably end up with something far worse in terms of user experience for us on the publisher’s side.
What about using WordPress as a data source and then using WordPress’s REST (or even GraphQL) API to pull in data? This technical solution could work, but creates a disconnect between the publishing side and the viewing side. How would you preview a post when you essentially decoupled the CMS from the data loading? How would you show the correct URL in the editing interface when the WordPress editor lives on a different server? (Or can you combine an SPA codebase in a PHP app?)
My current conclusion is that WordPress is just too powerful to replace, but the rest of our website can perfectly run in Svelte. If the WordPress runs on a subdomain, and the portfolio and every other page of the site is managed by a Svelte codebase, where both sites share the same header and footer, we might just have the best of both worlds – or we might just have created a technical monster.
Svelte is picking up steam, with multiple Svelte events in the world, you can find out about them via https://twitter.com/sveltesociety
I personally heard about a meeting in Amsterdam, one in Tokyo… there’s many things going on. Let’s hope some of these events will record their talks so we can all learn more about Svelte.
Speaking of recorded talks, there is a stream of the NYC event, with 3 talks, including one by Rich Harris, creator of Svelte.
In March we will sit together for the first Belgian event.
In the meantime, if you can’t wait to get started, you can give Svelte a try by following the official tutorial.
Support is available via Discord in the #support channel. People are friendly to beginner questions so don’t hesitate to ask something.
Regarding the event, we want to thank Lightspeed HQ for hosting us. LightSpeed is a POS solution that has an office in Ghent, Belgium.
The current attendee limit is 15. We might raise it to 20 people.
Ik keek onlangs nog eens naar Eyes Wide Shut, en besloot dat toch een bijzonder goede film is. Ik refereer af en toe in een melige bui naar een scéne uit Boyhood. En als ik nog eens nadenk over ooit een film maken, dan is Any Way The Wind Blows de eerste referentie die over de tong rolt.
Ik keek één aflevering van Over water, ik ga er nog eentje bijdoen, maar ik ben niet helemaal gegrepen.
Ik wil nu de Before reeks (Before Sunrise / Before Sunset / Before Midnight) herbekijken, waar ik erg fan van was de eerste keer dat ik dat bekeek.
Ik heb het steeds minder voor fantasieverhalen. Je zou me niet kunnen overhalen om een heel seizoen van The Mandalorian of het nieuwe Star Trek: Picard te zien (als dat al beschikbaar zou zijn in België). Ik heb wel genoten van The Witcher, maar dat was eerder een uitzondering.
Ik vond deze post terug in mijn drafts. Omdat deze slechte beslissing wetgevende realiteit aan het worden is (zelfs voor kinderen vanaf 12 jaar!), en de post actueel blijft besloot ik deze toch te publiceren. Dit werd oorspronkelijk geschreven op 3 november 2018.
Als je iets goed wil beveiligen, werk je tegenwoordig met tweefactorauthenticatie.
Je zorgt er voor dat er twee factoren zijn die bewijzen dat jij bent wie je zegt. Die twee factoren kunnen verschillende vormen aannemen. Vaak is het de smartphone met een authenticatiemechanisme via een app en een wachtwoord (time based authentication o.a. Google, de meeste banken). Het kan ook een sleutel op je computer zijn in combinatie met een sleutel op de server, gecombineerd met een wachtwoord (key based authentication o.a. Github).
Vele smartphones hebben ook een implementatie van de vingerafdruk om je aan te melden (bv. Touch ID van Apple). Je vingerafdrukdata wordt opgeslagen in een beveiligde laag.
Hoe veilig die data effectief is, is natuurlijk relatief. Vanaf iets beveiligd kan worden kan het ook gehackt worden. De ene implementatie is de andere ook niet. Er wordt wel eens gegrapt of je graag je informatie hackbaar wil maken op Russische, Amerikaanse of Chinese servers.
Of dit hacken dan effectief gebeurt is ook een functie van een aantal zaken. Is er iemand gebaat met de data in kwestie? Hoe moeilijk is het om iets te hacken?
De Belgische overheid is van plan om vanaf mei 2019 voor de identiteitskaarten het verplicht te maken om je vingerafdrukken mee te geven.
Dit is al zo met de reispas (voor 2 vingers, met een nogal crummy scanmethode, voor zover ik weet).
Eenieder die al eens gereisd heeft naar een land als de VS of Japan zal ook zijn vingerafdruk hebben moeten tonen bij de grenscontrole.
Ik vind dit niet onlogisch. Als land moet je weten wie je land binnenkomt. Voor de veiligheid, maar ook om illegale immigratie tegen te gaan. Maar als je de Belgisch identiteit hebt en naar je eigen land reist, moet je deze grotere controle in mijn ogen niet ondergaan.
Ik ben dus altijd blij om in Zaventem af te zwaaien naar de rij “EU onderdanen” en mijn gewone Belgische identiteitskaart te tonen aan de grenscontrole. Als ik in Japan of de VS aan de grenscontrole kom voel ik me dan weer niet echt welkom.
De stellingname van Jan Jambon (Zevende dag, 28 oktober 2017) is dat het plaatsen van de vingerafdrukken op de eID dient om identiteitsfraude aan te pakken. Als je identiteitsfraude pleegt, en je dus voor doet als iemand anders, is de kans veel groter dat je criminele feiten wil plegen.
Ik volg deze logica, maar moeten we daarom 11,5 miljoen Belgen hun vingerafdrukken gaan opslaan in een database?
Aangezien biometrische data een factor is in ieders persoonlijke beveiliging vind ik het gevaarlijk om die data in een externe database te stoppen die gehackt kan worden. Biometrische data verander je ook niet zomaar – je vingerafdrukken blijven hetzelfde. Eén lek ooit en deze “factor” is niet meer veilig.
Anderzijds is het ook maar 1 van de 2 factoren die een “hacker” nodig heeft als iets goed beveiligd is. Als we grenscontrole beschouwen heb je naast je legitieme documenten ook nog je foto, dus op zich zijn er al meerdere factoren.
In India kan je de database met vingerafdrukken van meer dan 1 miljard Indiërs volgens Vice kopen voor tien dollar.
Als je in een hypothetische situatie identiteitsfraude wil plegen, en dus een Belgische eID wil vervalsen, zou je dan in de toekomst op de zwarte markt ook zo’n database kunnen kopen?
Dan zou je nog toegang moeten hebben tot de software om zo’n eID te maken (wellicht verkrijgbaar bij elk gemeentebestuur op oudere, hackbare computers) Dan zou je de vingerafdruk-gegevens van jou moeten omwisselen met die van iemand anders.
En dan zou je nog genoeg op de pasfoto moeten lijken om een (grens)controle te doorstaan.
Eén probleem met overal zulke data te gaan opslaan is dat het gebruik ervan een hellend vlak is. Als de data er is, kan die gebruikt worden. Voor positieve en negatieve doeleinden.
We weten totaal niet welke regering we gaan hebben binnen 5 jaar, 10 jaar, 20 jaar. Wat als er een opmars is van extremisme? Stel dat de PVDA aan de macht komt. Willen we dan elke dag met het overheidsequivalent van Touch ID “badgen” om te bewijzen dat we aan het werk zijn voor de Grote Leider?
Michaël van Peel zegt het goed – uit “Van Peel Overleeft 2013” volgende clip:
Naar wat ik lees zijn ze in Nederland zijn ze al eens door dit debat gegaan, met eerst een goedkeuring en er na een afschaffing.
De laatste maanden wordt technologie telkens opgehouden als een schild. Ik vind dat er soms te veel geloofd wordt in technologie als oplossing van problemen (zie ook mijn vorige blogpost).
Een technologisch idee wordt uiteindelijk software. Als je een feature implementeert moet je ze ook kunnen ondersteunen.
Ik zie er weinig in om elke dienst bevolking in Vlaanderen te leren hoe ze vingerafdrukken moeten opslaan, om die dan via slechte software te beheren. Dit kost ook handenvol geld, terwijl we net moeten besparen in de overheidsuitgaven.
Is dit allemaal echt wel nodig? Kan de overheid zich niet iets afzijdiger houden in plaats van technologie op te houden als heilige graal? Kunnen we niet beter mínder doen, in plaats van elk probleem op te lossen met een overdaad aan technologie die toch niet ondersteund kan worden?
A few days ago I watched Rich Harris’s talk at JSCamp. It offers a different perspective on Svelte than the talk I usually recommend when learning about Svelte – which is called Rethinking Reactivity.
This talk is focussed on the idea “write less, do more” which was jQuery’s tagline.
Rich Harris says that one of the benefits of Svelte is writing less code. Because code is terse there is less boilerplate, which leads to less bugs. It also makes code more understandable. As a reader you have to follow less code paths and more code is visible on a single screen without scrolling. This leads to a better understanding.
Svelte is fast and the developer experience is excellent – but every framework claims this.
Rich realised that the unique part about Svelte’s compiler based approach is that it expands the problem space the framework can operate in.
Since it’s a compiler, it can do more, in theory the compiler can grow larger as long as the bundle sizes it generates stay small.
This offers possibilities such as code linting without bringing in another dependency. For example, Svelte warns when using the autofocus attribute on form fields because it is generally advised against, because it causes accessibility issues.
What about the “do more” part? Anyone who has learned jQuery might remember how easy it was to fade something in and out. Suddenly something that was out of your grasp before, you were now able to do. jQuery-based code has gotten a lot of criticism over the past years but let’s not forget that it was many developers’ superpower for a long time.
Taking things back to Svelte, I have a similar feeling. I’ve never been a hardcore developer. But Svelte enables me to make things that I previously could not do. Rich talks about where he wants Svelte to go – he wants to bring more people to the web, make coding interactive experiences more accessible instead of leaving it only to those who happen to very skilled at blindly manipulating symbols.
As for me, I want to do the same. I think web development shouldn’t be as hard as we tend to make it. There is a lot of overengineering in code out there. From a community perspective there is a lot of gatekeeping. Think “you are not a real developer if…”.
I remember when I got a computer and started tinkering with creative apps and later with HTML and CSS. I never got it until someone explained it well. Through reading many resources and being in the field for years I know what I know now; at the same time I feel the path should be easier.
We should break barriers and enable everyone to create. I can totally behind a framework like Svelte which is first of all just a great framework but secondly, where the original author has lofty goals that I can stand behind.
If you are interested in Svelte, I am organising an event on March 13th in a new Meetup group called Svelte Society Belgium.
It will be a code-along where we will code a small application together. There are not that many spots, so make sure to register! You can register using this link.
Ik heb met het fantastische Miro een brainstorm gemaakt over hoe mijn 2020 er moet uit zien, en op werkvlak zie ik dat er een duidelijke verschuiving is van wat ik wil doen.
Ik maakte de voorbije 1,5 a 2 jaar al een verschuiving van design naar design management. Nu is het voor mij heel duidelijk dat ik in de plaats van zelf veel designprojecten op te leveren ik veel meer zie in het opleiden van mensen om dat op een goede manier te doen.
Eén van de zaken die ik een nieuwe kans wil geven is meer gastlessen geven op scholen. Ik heb dit ooit eens gedaan en dat viel toen een beetje tegen (het was vrijdagochtend en er letten maar weinig mensen op :)) maar ik geef het een nieuwe kans.
Daarnaast zijn er de community events. Vorig jaar organiseerde ik een evenement over design systems. In de zomer ging mijn interesse terug naar front-end en werd ik geïnteresseerd in het framework Svelte.
Daar moest natuurlijk iets mee gedaan worden, dus nu is er de Svelte Society Belgium, waarmee we in maart een 1e evenement organiseren. Dit wordt een code-along waar we een kleine web app bouwen.
Ik ben van plan om een combinatie van Figma en Svelte als methode te gebruiken om web design + development aan te leren op een moderne manier. Hoe dat juist tot uiting gaat komen moet ik nog bedenken. Maar voor mij zijn dit de tools van de toekomst.
Er moet natuurlijk ook brood op de plank komen. Naast UI design projecten met Mono wil ik mijn commerciële Figma workshop op regelmatige basis beginnen herhalen. Op 30 januari is de tweede editie. De eerste was heel tof, ik heb me er zelf mee geamuseerd, en wegens een ziekte en meer geïnteresseerden dan ik dacht is er snel een 2e editie. Misschien kan dit wel iets herhalend worden, we zullen zien.
Ik heb gisteren mijn rechterhand gebroken – en typ dit bericht onhandig met 1 linkerhand en een beetje rechterhand. Dat deed me denken aan de inclusive graphic van Microsoft:
Ten eerste, hulde voor ons Belgische gezondheidszorgsysteem: van spoed naar radiografie naar een arm in het gips: 2 uur. Wauw. UZA in Edegem ftw?
Wat betreft het ongemak, ik moet zeggen dat het wel meevalt, maar alles zal 50% trager gaan de komende weken vrees ik. En sommige taken eerder 100% trager of gewoonweg niet.
Ik ging iets actiefs doen met de rest van mijn vrije tijd maar ik ga me wegens fysiek incapabel maar op iets intellectueels storten denk ik. Ik heb nog een stapel boeken liggen.
Aujourd’hui je vais travailler sur le champ. Planter des tulipes. Un changement d’en face développer pour 3 jours et juste sortir pour acheter de la nourriture et du fitness. A l’extérieur! C’est une belle journée, nous avons de la chance.
The structure is more or less the same as other years.The content might be interesting to some (as if there are not enough end of year lists already ;)), but for me it’s my personal excuse of the year to play with some technology.
This post is a technical write-up of some of the aspects of building this website.
Powered by Svelte
This year I got really interested in Svelte, so it was only natural to use Svelte for my yearly tech exploration. Svelte offers an incredible developer experience and highly optimized bundle sizes.
I used the Svelte starter template together with a new file-based router project called Routify.
?Svelte lovers, head up. I started a new meetup group called Svelte Society Belgium. We are organizing the first event in March. You can join the group and find out more here.
The main advantage from a viewer standpoint is no page reloading – the changes from page to page are instant. Using Svelte in general led to some new possibilities in regards to animation and smoothness, but also led to new problems. Nothing that we can’t fix of course!
Design
In 2018 I went content-first, but this year I went design-first. I more or less created all of the designs first, then implemented them as opposed to last year.
I tried out the new AutoLayout features in Figma to create an accurate design. It was quite handy to have a few auto-resizing components
As my colleagues will know, I am not the one for clean design files, I just visualize what I need to visualize as fast as I can then and then move on.
So if you are curious, you can check out the design file here; but don’t expect a document full of clean layers.
?Commercial break. I am giving a new Figma workshop on January 30, 2020. You can find out more here.
Content
During the year I logged the films I saw in Notion. This has been an incredible tool for us at Mono and I also use it for my “personal” things. Here’s a screenshot of my film log.
Looking at this I should really add Spider-Man: Into the Spiderverse to my list. Talking about missing content, the series page should also include Succession.
I also thought about a podcasts section but didn’t get to it (even though I listened to a lot of podcasts!).
I used images I found on Google Images, and some of the content is from IMDB. I hope that’s alright and put the usage of this in the disclaimer.
Klim offers test downloads for all of their fonts. You can download the package of test fonts on their site.
What I like about these foundries is that they have permissive licenses that are just a one-time purchase. When I make a website I don’t want to worry about the font licensing for years. With our Mono website we use Benton Sans and every year I have to deal with the bill and administration for that.
I plan to change the typography of this website to Untitled Sans as well. I have my own personal “brand” that no one ever sees (except the recipients of my invoices :D), and I slowly want to transfer it over to this website as well.
Routing
I put a version of the source code on Github that people could use for learning purposes.
You can see in /pages/ that the different routes are simply files: albums.svelte, series.svelte etc. There is a _fallback.svelte for the 404 and a _layout.svelte which contains the general layout used by every page.
The Routify examples site provides more examples. My needs were rather simple, and I got this up and running quite fast.
Animation
An example of animation is the fading of the albums on the albums page. Implementing this was as simple as writing this:
Notice that when animating out, we set the duration to 0, as otherwise the animation will delay the routing.
Another example of animation is the slider on the games page. I implemented it based on this REPL I had made before, which in turn was based on someone else’s work. If you are that person, please tell me so I can credit you.
For the slider, I am using a custom easing function called hslide.js.
It has to be noted that Svelte’s easing functions are simply mathematical functions, such as this one:
function expoInOut(t) {
return t === 0.0 || t === 1.0
? t
: t < 0.5
? +0.5 * Math.pow(2.0, 20.0 * t - 10.0)
: -0.5 * Math.pow(2.0, 10.0 - t * 20.0) + 1.0;
}
You can import functions from Svelte, and then use them:
import { expoInOut } from 'svelte/easing'
The slider as it is is nicely abstracted away to its own component.
Within that component, there are scripts and styles specific to the slider. In this case, I chose to keep most code related to the slider local to the component.
I quite like the clamp function in this code:
let cur = 0;
function changeSlide(slide) {
cur = slide;
}
const clamp = (number, min, max) => Math.min(Math.max(number, min), max);
function prev(e) { cur = clamp( --cur, 0, slides.length-1 ) }
function next(e) { cur = clamp( ++cur, 0, slides.length-1 ) }
What is “clamping” then? clamping is used to restrict a value to a given range.
A clamp function clamps a value between an upper and lower bound. It takes three parameters: a minimum value, a preferred value, and a maximum allowed value.
Side note: Svelte and the power of the REPL
Think of Svelte’s REPL as a sort of codepen to save your Svelte experiments. The REPL provides shareable links to Svelte code.
Throughout the year I am saving bits of code here and there which I can reuse in my projects. For example, I can’t wait to use this radial selector or do something with maps.
Scrolling: set the scroll to top when visiting new pages
Since an SPA simply reloads the content, but the visitor’s expectation is that when you visit a new page you end up at the top, I had to set the scroll position manually:
(A new version of Routify will support this automatically.)
Responsive images
When you have a few days to make something, you have to make some choices, and implementing responsive images did not make the cut.
What are responsive images?
First of all, what do I mean by responsive images? In short, it’s loading the right image based on the viewport. For example, if you have a viewport of 320px wide, and a screen that has a pixel density of 2x, the widest image you will ever need (bar zooming) is 640px. If you see something on a 4K screen, at 3840×2160, but the website image container maxes out at 1280, and the screen is 1x, then the max width you will need is 1280.
Thus, given a combination of instructions to the browser and providing the right images on your server, you can provide the end user with a highly optimized experience. Instead of loading lots of heavy images they could load specifically the images that are optimized for their environment without any quality loss.
Implementations
I thought about responsive images a lot though. In our current implementation of the Mono website, and also this very website, responsive images are handled in part by WordPress itself.
The server generates image sizes on upload, and when used in a post, provides the right markup automatically.
Now, in a Svelte environment, there is no CMS, there is no server doing thing for you, so you have to do it yourself.
Generating the smaller images
In the past I have used packages like gulp-imagemin and others to generate images. I read up about Sharp now (thx Jérôme), but didn’t use it much except for a small experiment (thank you @Coma).
In my experiment I noted that Sharp is blazingly fast, but generating the right mages is creating workflow problems in itself. Something that I would only want to work on for a larger project.
I’ve always thought that putting the implementation work with the user was a bad idea. My colleague and business partner Xavier wrote about this a long time ago “The Responsive Image Solution Does Not Belong in HTML”.
Responsive images conclusion
In the end I didn’t get far with actually implementing responsive images, and the images in the deployed version are not responsive.
I used a combination of Save for web using Photoshop CS 2020 (I hate paying so much yearly for only using a few functionalities but OK) and the website TinyJPG.com to get to smaller images.
Dark mode
Naturally, with all the dark mode hype, I had to implement a dark mode.
I didn’t use CSS variables or anything, just manually declared an alternative in the context of the SCSS.
I find this to be more manageable than cross-referencing lots of variables, especially because there are often subtle tweaks that you need to make to the colours.
This also falls nicely in line with my philosophy of keeping code portable across projects.
Deployment
This was my first time deploying an “Single Page Application” (SPA) with multiple pages (confusing, isn’t it?); so I ran into a little problem where links wouldn’t work. Then I remembered that I would probably need to redirect all requests to index.html. On an Apache server, you can do that as follows:
Then later on, I wanted to link to images directly, and the requests to images would be caught by this RewriteRule, so I had to extend the rewrite conditions:
Routify is a new-ish project, so I had some small implementation issues, but Jakob, the author was super responsive on Github. Eventually we even got into a chat and I started logging issues and thinking about how they could be solved to move this project forward.
CSS strategy: framework for general components + local, scoped CSS through Svelte
Svelte has built-in CSS scoping to a Svelte component. But just because a language has a feature doesn’t mean you have to use it for everything. I see this a lot in other people’s SCSS code: they go crazy with all the Sass features and in the end have a bunch of complex code.
For most of the CSS, I went with a separate SCSS file that got compiled separately. I found it quite handy to have an existing div-based grid implementation readily available (code), as well as a setup for differentiating between “styled” HTML and HTML that should be left unstyled (a simple version of this logic can be found in Ygdir here).
This past January I wrote about the need for a new CSS framework. These thoughts have crystallised into a new project called Ygdir, which is pretty early stage now. The general idea behind Ygdir is that is a convention-first framework.
Home page graphic
For the home page graphic, I was trying some things with generating SVG with Svelte. This kind of code generates a bunch of SVG circles:
<script>
let gridSize = 14;
let dotSize = 1.5;
let countCols = 30;
let countRows = 10;
</script>
<svg>
{#each Array(countCols) as _, i}
{#each Array(countRows) as _, j}
<circle cx="{dotSize+(i*dotSize*gridSize)}" cy="{dotSize*gridSize*j}" r="{dotSize}" />
<circle cx="{dotSize+(i*dotSize*gridSize)+10}" cy="{dotSize*gridSize*j+8}" r="{dotSize*1,2}" />
{/each}
{/each}
</svg>
I had lots of ideas for this graphic, for example what I wanted to do is animate the circles based on whether you were hovering over them, and then animating nearby circles, creating some a sort of “shockwave” pattern.
For the globe (circle) in the illustration, I was thinking I wanted to animate a radial gradient in some way. I had this concept of the sun rising, or a 3D sphere full of stars.
I also wanted it to react to mouse movement in a natural way. I didn’t get to this, and I also believe implementing that requires a lot of studying first to get smooth with graphics programming.
I ran out of time so these graphics programming experiment will be something for 2019. For the responsive version, I even completely hid the graphic on the homepage because I didn’t want to work on making a responsive dynamic graphic with animated layers. Pick your battles I would say.
Data logic
I am directly importing JS data in my Svelte templates:
In 2017 I experimented with using AirTable. In 2018 I looked into using a headless CMS.
The thing here is that the data is simple enough to manipulate directly, so I couldn’t be bothered to set up a big technology stack for the content.
This does remain an interesting issue to work on. Where do you manage the data? How do you link it properly? What is the “backend” and how do we provide the right mix between editability by devs and non-devs? We do not create a lot of content websites in our company, so we don’t have to deal with this problem often, but it’s an area that interests me.
I would love to experiment with a headless CMS, but the current offering does not really inspire me. Although to be honest I only gave Netlify’s CMS a real try. Maybe I should do more tests. There’s a lot of tech out there: TinaCMS – Contentful – Forestry etc. – or I should maybe just do a test with headless WordPress.
Conclusion
In my 2018 writeup I wrote: In a lot of ways the end result is exactly what I made last year, but the technical underpinnings have changed.
You could say the same about this year’s version. In a lot of ways the result is similar, but under the hood, a lot of changes have been made. The biggest one this year is using Svelte, which in my mind is a big upgrade from using a static site generator.
In some ways it’s also a downgrade – I’m from the school of progressive enhancement, and a JS error might just break this site, making is quite fragile. I’m also not sure about the accessibility of it all. But I felt like I needed to make some moves and move on from regular old HTML/CSS/JS; the industry is moving towards a certain way of building things and you have to work with it to form your opinion. Maybe in a few years I’ll decide that this “SPA” thing was a really bad idea.
Please comment with your thoughts – I am curious as to what people think about this project, whether I should continue doing it, what you picked up from my technical write-up.