Recherche avancée

Médias (91)

Autres articles (87)

  • Ecrire une actualité

    21 juin 2013, par

    Présentez les changements dans votre MédiaSPIP ou les actualités de vos projets sur votre MédiaSPIP grâce à la rubrique actualités.
    Dans le thème par défaut spipeo de MédiaSPIP, les actualités sont affichées en bas de la page principale sous les éditoriaux.
    Vous pouvez personnaliser le formulaire de création d’une actualité.
    Formulaire de création d’une actualité Dans le cas d’un document de type actualité, les champs proposés par défaut sont : Date de publication ( personnaliser la date de publication ) (...)

  • Organiser par catégorie

    17 mai 2013, par

    Dans MédiaSPIP, une rubrique a 2 noms : catégorie et rubrique.
    Les différents documents stockés dans MédiaSPIP peuvent être rangés dans différentes catégories. On peut créer une catégorie en cliquant sur "publier une catégorie" dans le menu publier en haut à droite ( après authentification ). Une catégorie peut être rangée dans une autre catégorie aussi ce qui fait qu’on peut construire une arborescence de catégories.
    Lors de la publication prochaine d’un document, la nouvelle catégorie créée sera proposée (...)

  • Les tâches Cron régulières de la ferme

    1er décembre 2010, par

    La gestion de la ferme passe par l’exécution à intervalle régulier de plusieurs tâches répétitives dites Cron.
    Le super Cron (gestion_mutu_super_cron)
    Cette tâche, planifiée chaque minute, a pour simple effet d’appeler le Cron de l’ensemble des instances de la mutualisation régulièrement. Couplée avec un Cron système sur le site central de la mutualisation, cela permet de simplement générer des visites régulières sur les différents sites et éviter que les tâches des sites peu visités soient trop (...)

Sur d’autres sites (3761)

  • How to increase conversions to meet your business goals

    8 septembre 2020, par Joselyn Khor — Analytics Tips, Marketing

     Through optimizing your messaging, content, or your page layouts, you can increase conversions by getting your visitors through a clear pathway to achieve your business goals.

    Conversion Rate Optimization

    When we talk about optimizing websites to improve and increase conversions, we’re really talking about conversion rate optimization (CRO).

    CRO is the process of learning what the most valuable content/aspect of your website is and how to best optimize this for your visitors to increase its chance to convert. It typically involves generating ideas for elements on your site or app that can be improved, learning which pathways visitors are most likely going to take to conversion and then validating those assumptions through A/B testing and multivariate testing to transform learning into actionable insights.

    Conversion Rate

    The conversion rate is expressed as a % and the goal for any business should be to increase the % of conversions for any given goal e.g. in February a website had 200 newsletter sign-ups from 1,000 visitors on its sign-up page, a conversion rate of 20%. CRO should be used to increase the sign-up rate from 20% to 25%, and then eventually from 25% to 30% and so on.

    CRO cheat sheet

    You need to consider your website or business’ objectives (bigger picture) as well as your website goals (smaller achievements). Whatever the aim of your website, it’s crucial for this to be your starting point. Figure out what you want your website to do and what you want visitors to get from it. When you do that, you’ll know what conversions to focus on.
    • Define your business/website’s objectives. Do you want the website to drive sales ? Is the website a hub to raise awareness for a charity ? Do you want to increase readership for your news site ?
    • Define what your conversion goals are. This helps you narrow your focus so you follow a path to meet your overall objectives. By defining these, you clarify for yourself the next actions you should take, such as wanting to funnel users through to a sign up landing page. Then you’ll need to optimize and test your sign up landing page. If conversions are low, then tweak it and measure the results until you find you’ve increased conversion rates.
    • Conversion goals can include :
      • Purchases in your ecommerce store
      • eBook downloads
      • Sign ups to your mailing list
      • Visitors successfully filling in a contact form
    • Figure out what your Key Performance Indicators (KPIs) are and the metrics you need to focus on to achieve them.

    1. Set goals

    “Make Sure Goals Are Clearly Understood. To prove the value of an analytics-focused company, any project you take on needs to have clear goals. If you don’t have a goal in mind you’ll fail. Everyone involved in the project needs to be aligned around the goals.”

    - Lean Analytics : Use Data to Build a Better Startup Faster

    A goal is the measure of a successful action that you want your visitors to take. The more goals you track, the more you can learn about behavioural changes as you implement and modify paths that lead to conversions over time.

    Matomo goal feature

    You’ll understand which channels and campaigns (SEO, PPC, newsletter, blogging etc.) are converting the best for your business, which cities/countries are most popular, what devices are working and how engaged your visitors are before converting. Learn more

    2. Set Heatmaps

    This is vital to show how your visitors are engaging with your website, blog pages, signup and sales pages. If you want to learn how your visitors really engage with your website to increase conversions, Heatmaps lets you see the results visually without any guesswork.

    Matomo's heatmaps feature

    By showing where your visitors try to click, move the mouse or how far down they’re scrolling on each page, you can effortlessly discover how your visitors truly engage with your most important web pages. Rather than guessing, rely on facts to prove if the changes you make actually improve your website or not. Learn more

    How to improve conversion rates with Heatmaps :

    • If you’ve got important information that will sell your service/product or bring you loyal followers, make sure it’s in the hot zones as shown in your heatmaps.
    • Try to rearrange parts of your pages to see if that increases engagement.
    • Make it easy for people to take important actions by having the CTA above-the-fold where 100% of visitors see it. Make sure you don’t clutter this section with too many messages or actions.
    • You can also identify areas to add links as heatmaps shows where people want to click.
    • Find what content is most popular on the page

    3. Session Recordings

    This is a conversion research technique where you learn what your users are trying to do and make sure your website is optimized to give them what they want. With Session Recordings you can playback all the interactions your visitors took on your website, such as clicks, mouse movements, scrolls, resizes, form interactions and page changes in a video. Truly understand how real visitors are using your website and what experiences they’re having.

    Also, by understanding what’s working you’re increasing the usability of your website, Session Recordings allow you to identify problem areas as well as where users are getting stuck. Learn more

    Session Recordings

    How to improve conversion rates with Session Recordings : For example, on a product landing page, you see your visitor highlighting specific words and putting it into search. With this you can observe what they’re trying to find and what they’re actually interested in. As you tweak the page to ensure what the visitor wants can be easily found, you’re taking steps to increase the chance for more conversions.

    4. A/B Testing

    Test anything and test anywhere to increase your conversions. Grow your website by comparing different versions of your landing pages to determine what works best for your users. Subtle tweaks across different versions of your landing pages can have a significant impact on converting incoming traffic.

    Matomo's a/b testing feature

    The changes for each landing page could be :

    • A different headline
    • Less copy vs more copy
    • Different calls-to-action
    • Colour schemes, forms, fonts, links, testimonials,
    • Or, it could be an entirely different page layout altogether.

    The idea is to see if either page A or page B (or C or D) was most successful in getting your visitors to the next step in the conversion funnel. Learn more

    How Matomo used A/B Testing : For our sign up page we tested three different CTAs and found how phrasing words differently could help improve conversion rates. Both “Start improving your websites” and “Start converting more users now” were stronger CTAs and converted 7% more than, “Start my free 30-day trial”.

    5. Form Analytics

    Form Analytics gives you powerful insights into how your visitors interact with your forms (like cart, sign-up and checkout forms).

    Form Analytics

    Online forms can come in thousands of different variations. It’s an area on your website that if not done right, could lead to you missing out on converting a large portion of your visitors. Rely on facts when you change your forms. Learn more

    How to improve conversion rates with Form Analytics : By proving whether your form is doing better when you change it and by how much. This lets you consistently increase form submission rates (conversions) on your website which is crucial to the success of your business.

    6. Funnels

    At a glance you will learn the steps (actions, events and pages) your users go through to the desired outcomes you want them to achieve whether it’s a sale, sign-up or any other particular goal you have defined.

    Funnels feature

    Looking at the entire conversion funnel and focusing on usability, you’ll be able to identify where your visitors are having problems, where they aren’t understanding the flow of your webpages and identify obstacles that get in the way of your users reaching that end goal. Learn more

    How to improve conversion rates with Funnels : Learn what makes your visitors take action (or what stops them) in progressing to the next step in the conversion funnel. At each step, you’ll discover what content/layout resonates with your visitors and you can optimize your website to have the greatest impact on your business.

    7. Behaviour

    This is one of the most important features to help you optimize your website for conversions. Learning visitor behaviour is a driving force to increase conversions. How ? It lets you identify where you could be taking action to increase conversions. You get to learn first-hand what content or feature on your site is or isn’t working for your visitors. 

    Behaviour feature

    Engagement is essential to help increase conversion rates. If your visitors aren’t interested in the content on your site, then there’s very little chance they’ll be interested in what you have to offer. Learn more

    How to improve conversion rates with Behaviour : Get started by reducing bounce rates on important pages, testing messaging on your most popular entry pages, testing on the highest exit pages to reduce visitors leaving the site, learning pathways through Users Flow and Transitions to see if users are taking pathways that lead them to conversions or are the journeys currently long or go in odd directions. Discover how your visitors are responding to your content. The happier your visitors are to stay on your site, the more likely they’ll be able to move through the journey to help you achieve the goals you’ve set for your site.

    Do privacy-focused industries need conversion optimization ?

    For industries that place extra emphasis on privacy and security, Matomo is a complete analytics tool that can cater for all your needs. You get the full benefits of a web analytics and conversion optimization platform as well as peace of mind knowing Matomo places emphasis on security/privacy and adheres strictly to GDPR.

    If you operate in a data sensitive industry like in government, healthcare, finance, education etc. you can rest assured knowing your user’s privacy is respected and that you will have 100% data ownership.

    Other conversion optimization metrics in Matomo to look at :

    Get a good indication that your conversion optimization efforts are working by knowing where to look and this starts by going through the metrics in your analytics. Below we list how you can make a start.

    “Best” metrics are hard to determine so you’ll need to ask yourself what you want your site to do. How do you want your users to behave or what kind of customer journey do you want them to have ?

    You can start with :

    • Decreasing abandonment rate
    • Decreasing bounce rate
    • Increasing interactions per visit
    • Reducing exit rates on pages that significantly impact your visitors to leave your site
    • Constantly test and learn what content resonates with your visitors
    • Look to advance more users through each stage of the conversion funnel
    • Improve your forms to increase submission rates
    • Always improve the conversion rate % for your goals e.g. if you currently have a 5% conversion rate for selling a product, aim for 10% ; if 30% of your visitors are downloading your e-book, then aim for 40%, then 50% and so on.

    Through optimizing your messaging, content or your page layouts, you will increase conversions by getting your visitors through a clear pathway to meet your website’s goal.

  • Blog series part 2 : How to increase engagement of your website visitors, and turn them into customers

    8 septembre 2020, par Joselyn Khor — Analytics Tips, Marketing

    Long gone are the days of simply tracking page views as a measure of engagement. Now it’s about engagement analysis, which is layered and provides insight for effective data-driven decisions.

    Discover how engaged people are with your website by uncovering behavioural patterns that tell you how well your site and content is or isn’t performing. This insight helps you re-evaluate, adapt and optimise your content and strategy. The more engaged they are, the more likely you’ll be able to guide them on a predetermined journey that results in more conversions ; and helps you reach the goals you’ve set for your business. 

    Why is visitor engagement important ?

    It’s vital to measure engagement if you have anything content related that plays a role in your customer’s journey. Some websites may find more value in figuring out how engaging their entire site is, while others may only want to zone in on, say, a blogging section, e-newsletters, social media channels or sign-up pages.

    In the larger scheme of things, engagement can be seen as what’s running your site. Every aspect of the buyer’s journey requires your visitors to be engaged. Whether you’re trying to attract, convert or build a loyal audience base, you need to know your content is optimised to maintain their attention and encourage them along the path to purchase, conversion or loyalty.

    How to increase engagement with Matomo

    You need to know what’s going right or wrong to eventually be able to deliver more riveting content your visitors can’t help but be drawn to. Learn how to apply Matomo’s easy-to-use features to increase engagement :

    1. The Behaviour feature
    2. Heatmaps
    3. A/B Testing
    4. Media Analytics
    5. Transitions
    6. Custom reports
    7. Other metrics to keep an eye on

    1. Look at the Behaviour feature

    It allows you to learn how visitors are responding to your content. This information is gathered by drawing insight from features such as site search, downloads, events and content interactions. Learn more

    Matomo's behaviour feature

    Matomo’s top five ways to increase engagement with the Behaviour feature :

    Behaviour -> Pages
    Get complete insights on what pages your users engage with, what pages provide little value to your business and see the results of entry and exit pages. If important content is generating low traffic, you need to place it where it can be seen. Spend time where it matters and focus on the content that will engage with your users and see how it eventually converts them into customers.

    Behaviour -> Site search
    Site search tracks how people use your website’s internal search engine. You can see :

    • What search keywords visitors used on your website’s internal search.
    • Which of those keywords resulted in no results (what content your visitors are looking for but cannot find).
    • What pages visitors visited immediately after a search.
    • What search categories visitors use (if your website employs search categories).

    Behaviour -> Downloads
    What are users wanting to take away with them ? They could be downloading .pdfs, .zip files, ebooks, infographics or other free/paid resources. For example, if you were working for an education institution and created valuable information packs for students that you made available online in .pdf format. To see an increase in downloads meant students were finding the .pdfs and realising the need to download them. No downloads could mean the information packs weren’t being found which would be problematic.

    Behaviour -> Events
    Tracking events is a very useful way to measure the interactions your users have with your website content, which are not directly page views or downloads.

    How have Events been used effectively ? A great example comes from one of our customers, Catalyst. They wanted to capture and measure the user interaction of accordions (an area of content that expands or closes depending on how a user interacts with it) to see if people were actually getting all the information available to them on this one page. By creating an Event to record which accordion had been opened, as well as creating events for other user interactions, they were able to figure out which content got the most engagement and which got the least. Being able to see how visitors navigated through their website helped them optimise the site to ensure people were getting the relevant information they were craving.

    Behaviour -> Content interactions
    Content tracking allows you to track interaction within the content of your web page. Go beyond page views, bounce rates and average time spent on page with your content. Instead, you can analyse content interaction rates based on mouse clicking and configuring scrolling or hovering behaviours to see precisely how engaged your users are. If interaction rates are low, perhaps you need to restructure your page layout to grab your user’s attention sooner. Possibly you will get more interaction when you have more images or banner ads to other areas of your business.

    Watch this video to learn about the Behaviour feature

    2. Set up Heatmaps

    Effortlessly discover how your visitors truly engage with your most important web pages that impact the success of your business. Heatmaps shows you visually where your visitors try to click, move the mouse and how far down they scroll on each page.

    Matomo's heatmaps feature

    You don’t need to waste time digging for key metrics or worry about putting together tables of data to understand how your visitors are interacting with your website. Heatmaps make it easy and fast to discover where your users are paying their attention, where they have problems, where useless content is and how engaging your content is. Get insights that you cannot get from traditional reports. Learn more

    3. Carry out A/B testing

    With A/B Testing you reduce risk in your decision-making and can test what your visitors are responding well to. 

    Matomo's a/b testing feature

    Ever had discussions with colleagues about where to place content on a landing page ? Or discussed what the call-to-action should be and assumed you were making the best decisions ? The truth is, you never know what really works the best (and what doesn’t) unless you test it. Learn more

    How to increase engagement with A/B Testing : Test, test and test. This is a surefire way to learn what content is leading your visitors on a path to conversion and what isn’t.

    4. Media Analytics

    Tells you how visitors are engaging with your video or audio content, and whether they’re leading to your desired conversions. Track :

    • How many plays your media gets and which parts they viewed
    • Finish rates
    • How your media was consumed over time
    • How media was consumed on specific days
    • Which locations your users were viewing your content from
    • Learn more
    Media Analytics

    How to increase engagement with Media Analytics : These metrics give a picture of how audiences are behaving when it comes to your content. By showing insights such as, how popular your media content is, how engaging it is and which days content will be most viewed, you can tailor content strategies to produce content people will actually find interesting and watch/listen.

    Matomo example : When we went through the feature video metrics on our own site to see how our videos were performing, we noticed our Acquisition video had a 95% completion rate. Even though it was longer than most videos, the stats showed us it had, by far, the most engagement. By using Media Analytics to get insights on the best and worst performing videos, we gathered useful info to help us better allocate resources effectively so that in the future, we’re producing more videos that will be watched.

    5. Investigate transitions

    See which page visitors are entering the site from and where they exit to. Transitions shows engagement on each page and whether the content is leading them to the pages you want them to be directed to.

    Transitions

    This gives you a greater understanding of user pathways. You may be assuming visitors are finding your content from one particular pathway, but figure out users are actually coming through other channels you never thought of. Through Transitions, you may discover and capitalise on new opportunities from external sites.

    How to increase engagement with Transitions : Identify clearly where users may be getting distracted to click away and where other pages are creating opportunity to click-through to conversion. 

    6. Create Custom Reports

    You can choose from over 200 dimensions and metrics to get the insights you need as well as various visualisation options. This makes understanding the data incredibly easy and you can get the insights you need instantly for faster results without the need for a developer. Learn more

    Custom Reports

    How to increase engagement with Custom Reports : Set custom reports to see when content is being viewed and figure out how engaged users are by looking at different hours of the day or which days of the week they’re visiting your website. For example, you could be wondering what hour of the day performed best for converting your customers. Understanding these metrics helps you figure out the best time to schedule your blog posts, pay-per-click advertising, edms or social media posts knowing that your visitors are more likely to convert at different times.

    7. Other metrics to key an eye on …

    A good indication of a great experience and of engagement is whether your readers, viewers or listeners want to do it again and again.

    “Best” metrics are hard to determine so you’ll need to ask yourself what you want to do or what you want your site to do. How do you want your users to behave or what kind of buyer’s journey do you want them to have ?

    Want to know where to start ? Look at …

    • Bounce rate – a high bounce rate isn’t great as people aren’t finding what they’re looking for and are leaving without taking action. (This offers great opportunities as you can test to see why people are bouncing off your site and figure out what you need to change.)
    • Time on site – a long time on site is usually a good indication that people are spending time reading, navigating and being engaged with your website. 
    • Frequency of visit – how often do people come back to interact with the content on your website ? The higher the % of your visitors that come back time and time again will show how engaged they are with your content.
    • Session length/average session duration – how much time users spend on site each session
    • Pages per session – is great to show engagement because it shows visitors are happy going through your website and learn more about your business.

    Key takeaway

    Whichever stage of the buyer’s journey your visitors are in, you need to ensure your content is optimised for engagement so that visitors can easily spend time on your website.

    “Every single visit by every single visitor is no longer judged as a success or a failure at the end of 29 min (max) session in your analytics tool. Every visit is not a ‘last-visit’, rather it becomes a continuous experience leading to a win-win outcome.” – Avinash Kaushik

    As you can tell, one size does not fit all when it comes to analysing and measuring engagement, but with a toolkit of features, you can make sure you have everything you need to experiment and figure out the metrics that matter to the success of your business and website.

    Concurrently, these gentle nudges for visitors to consume more and more content encourages them along their path to purchase, conversion or loyalty. They get a more engaging website experience over time and you get happy visitors/customers who end up coming back for more.

    Want to learn how to increase conversions with Matomo ? Look out for the final in this series : part 3 ! We’ll go through how you can boost conversions and meet your business goals with web analytics. 

  • Things I Have Learned About Emscripten

    1er septembre 2015, par Multimedia Mike — Cirrus Retro

    3 years ago, I released my Game Music Appreciation project, a website with a ludicrously uninspired title which allowed users a relatively frictionless method to experience a range of specialized music files related to old video games. However, the site required use of a special Chrome plugin. Ever since that initial release, my #1 most requested feature has been for a pure JavaScript version of the music player.

    “Impossible !” I exclaimed. “There’s no way JS could ever run fast enough to run these CPU emulators and audio synthesizers in real time, and allow for the visualization that I demand !” Well, I’m pleased to report that I have proved me wrong. I recently quietly launched a new site with what I hope is a catchier title, meant to evoke a cloud-based retro-music-as-a-service product : Cirrus Retro. Right now, it’s basically the same as the old site, but without the wonky Chrome-specific technology.

    Along the way, I’ve learned a few things about using Emscripten that I thought might be useful to share with other people who wish to embark on a similar journey. This is geared more towards someone who has a stronger low-level background (such as C/C++) vs. high-level (like JavaScript).

    General Goals
    Do you want to cross-compile an entire desktop application, one that relies on an extensive GUI toolkit ? That might be difficult (though I believe there is a path for porting qt code directly with Emscripten). Your better wager might be to abstract out the core logic and processes of the program and then create a new web UI to access them.

    Do you want to compile a game that basically just paints stuff to a 2D canvas ? You’re in luck ! Emscripten has a porting path for SDL. Make a version of your C/C++ software that targets SDL (generally not a tall order) and then compile that with Emscripten.

    Do you just want to cross-compile some functionality that lives in a library ? That’s what I’ve done with the Cirrus Retro project. For this, plan to compile the library into a JS file that exports some public functions that other, higher-level, native JS (i.e., JS written by a human and not a computer) will invoke.

    Memory Levels
    When porting C/C++ software to JavaScript using Emscripten, you have to think on 2 different levels. Or perhaps you need to force JavaScript into a low level C lens, especially if you want to write native JS code that will interact with Emscripten-compiled code. This often means somehow allocating chunks of memory via JS and passing them to the Emscripten-compiled functions. And you wouldn’t believe the type of gymnastics you need to execute to get native JS and Emscripten-compiled JS to cooperate.

    “Emscripten : Pointers and Pointers” is the best (and, really, ONLY) explanation I could find for understanding the basic mechanics of this process, at least when I started this journey. However, there’s a mistake in the explanation that left me confused for a little while, and I’m at a loss to contact the author (doesn’t anyone post a simple email address anymore ?).

    Per the best of my understanding, Emscripten allocates a large JS array and calls that the memory space that the compiled C/C++ code is allowed to operate in. A pointer in C/C++ code will just be an index into that mighty array. Really, that’s not too far off from how a low-level program process is supposed to view memory– as a flat array.

    Eventually, I just learned to cargo-cult my way through the memory allocation process. Here’s the JS code for allocating an Emscripten-compatible byte buffer, taken from my test harness (more on that later) :

    var musicBuffer = fs.readFileSync(testSpec[’filename’]) ;
    var musicBufferBytes = new Uint8Array(musicBuffer) ;
    var bytesMalloc = player._malloc(musicBufferBytes.length) ;
    var bytes = new Uint8Array(player.HEAPU8.buffer, bytesMalloc, musicBufferBytes.length) ;
    bytes.set(new Uint8Array(musicBufferBytes.buffer)) ;
    

    So, read the array of bytes from some input source, create a Uint8Array from the bytes, use the Emscripten _malloc() function to allocate enough bytes from the Emscripten memory array for the input bytes, then create a new array… then copy the bytes…

    You know what ? It’s late and I can’t remember how it works exactly, but it does. It has been a few months since I touched that code (been fighting with front-end website tech since then). You write that memory allocation code enough times and it begins to make sense, and then you hope you don’t have to write it too many more times.

    Multithreading
    You can’t port multithreaded code to JS via Emscripten. JavaScript has no notion of threads ! If you don’t understand the computer science behind this limitation, a more thorough explanation is beyond the scope of this post. But trust me, I’ve thought about it a lot. In fact, the official Emscripten literature states that you should be able to port most any C/C++ code as long as 1) none of the code is proprietary (i.e., all the raw source is available) ; and 2) there are no threads.

    Yes, I read about the experimental pthreads support added to Emscripten recently. Don’t get too excited ; that won’t be ready and widespread for a long time to come as it relies on a new browser API. In the meantime, figure out how to make your multithreaded C/C++ code run in a single thread if you want it to run in a browser.

    Printing Facility
    Eventually, getting software to work boils down to debugging, and the most primitive tool in many a programmer’s toolbox is the humble print statement. A print statement allows you to inspect a piece of a program’s state at key junctures. Eventually, when you try to cross-compile C/C++ code to JS using Emscripten, something is not going to work correctly in the generated JS “object code” and you need to understand what. You’ll be pleading for a method of just inspecting one variable deep in the original C/C++ code.

    I came up with this simple printf-workalike called emprintf() :

    #ifndef EMPRINTF_H
    #define EMPRINTF_H
    

    #include <stdio .h>
    #include <stdarg .h>
    #include <emscripten .h>

    #define MAX_MSG_LEN 1000

    /* NOTE : Don’t pass format strings that contain single quote (’) or newline
    * characters. */
    static void emprintf(const char *format, ...)

    char msg[MAX_MSG_LEN] ;
    char consoleMsg[MAX_MSG_LEN + 16] ;
    va_list args ;

    /* create the string */
    va_start(args, format) ;
    vsnprintf(msg, MAX_MSG_LEN, format, args) ;
    va_end(args) ;

    /* wrap the string in a console.log(’’) statement */
    snprintf(consoleMsg, MAX_MSG_LEN + 16, "console.log(’%s’)", msg) ;

    /* send the final string to the JavaScript console */
    emscripten_run_script(consoleMsg) ;

    #endif /* EMPRINTF_H */

    Put it in a file called “emprint.h”. Include it into any C/C++ file where you need debugging visibility, use emprintf() as a replacement for printf() and the output will magically show up on the browser’s JavaScript debug console. Heed the comments and don’t put any single quotes or newlines in strings, and keep it under 1000 characters. I didn’t say it was perfect, but it has helped me a lot in my Emscripten adventures.

    Optimization Levels
    Remember to turn on optimization when compiling. I have empirically found that optimizing for size (-Os) leads to the best performance all around, in addition to having the smallest size. Just be sure to specify some optimization level. If you don’t, the default is -O0 which offers horrible performance when running in JS.

    Static Compression For HTTP Delivery
    JavaScript code compresses pretty efficiently, even after it has been optimized for size using -Os. I routinely see compression ratios between 3.5:1 and 5:1 using gzip.

    Web servers in this day and age are supposed to be smart enough to detect when a requesting web browser can accept gzip-compressed data and do the compression on the fly. They’re even supposed to be smart enough to cache compressed output so the same content is not recompressed for each request. I would have to set up a series of tests to establish whether either of the foregoing assertions are correct and I can’t be bothered. Instead, I took it into my own hands. The trick is to pre-compress the JS files and then instruct the webserver to serve these files with a ‘Content-Type’ of ‘application/javascript’ and a ‘Content-Encoding’ of ‘gzip’.

    1. Compress your large Emscripten-build JS files with ‘gzip’ : ‘gzip compiled-code.js’
    2. Rename them from extension .js.gz to .jsgz
    3. Tell the webserver to deliver .jsgz files with the correct Content-Type and Content-Encoding headers

    To do that last step with Apache, specify these lines :

    AddType application/javascript jsgz
    AddEncoding gzip jsgz
    

    They belong in either a directory’s .htaccess file or in the sitewide configuration (/etc/apache2/mods-available/mime.conf works on my setup).

    Build System and Build Time Optimization
    Oh goodie, build systems ! I had a very specific manner in which I wanted to build my JS modules using Emscripten. Can I possibly coerce any of the many popular build systems to do this ? It has been a few months since I worked on this problem specifically but I seem to recall that the build systems I tried to used would freak out at the prospect of compiling stuff to a final binary target of .js.

    I had high hopes for Bazel, which Google released while I was developing Cirrus Retro. Surely, this is software that has been battle-tested in the harshest conditions of one of the most prominent software-developing companies in the world, needing to take into account the most bizarre corner cases and still build efficiently and correctly every time. And I have little doubt that it fulfills the order. Similarly, I’m confident that Google also has a team of no fewer than 100 or so people dedicated to developing and supporting the project within the organization. When you only have, at best, 1-2 hours per night to work on projects like this, you prefer not to fight with such cutting edge technology and after losing 2 or 3 nights trying to make a go of Bazel, I eventually put it aside.

    I also tried to use Autotools. It failed horribly for me, mostly for my own carelessness and lack of early-project source control.

    After that, it was strictly vanilla makefiles with no real dependency management. But you know what helps in these cases ? ccache ! Or at least, it would if it didn’t fail with Emscripten.

    Quick tip : ccache has trouble with LLVM unless you set the CCACHE_CPP2 environment variable (e.g. : “export CCACHE_CPP2=1”). I don’t remember the specifics, but it magically fixes things. Then, the lazy build process becomes “make clean && make”.

    Testing
    If you have never used Node.js, testing Emscripten-compiled JS code might be a good opportunity to start. I was able to use Node.js to great effect for testing the individually-compiled music player modules, wiring up a series of invocations using Python for a broader test suite (wouldn’t want to go too deep down the JS rabbit hole, after all).

    Be advised that Node.js doesn’t enjoy the same kind of JIT optimizations that the browser engines leverage. Thus, in the case of time critical code like, say, an audio synthesis library, the code might not run in real time. But as long as it produces the correct bitwise waveform, that’s good enough for continuous integration.

    Also, if you have largely been a low-level programmer for your whole career and are generally unfamiliar with the world of single-threaded, event-driven, callback-oriented programming, you might be in for a bit of a shock. When I wanted to learn how to read the contents of a file in Node.js, this is the first tutorial I found on the matter. I thought the code presented was a parody of bad coding style :

    var fs = require("fs") ;
    var fileName = "foo.txt" ;
    

    fs.exists(fileName, function(exists)
    if (exists)
    fs.stat(fileName, function(error, stats)
    fs.open(fileName, "r", function(error, fd)
    var buffer = new Buffer(stats.size) ;

    fs.read(fd, buffer, 0, buffer.length, null, function(error, bytesRead, buffer)
    var data = buffer.toString("utf8", 0, buffer.length) ;

    console.log(data) ;
    fs.close(fd) ;
    ) ;
    ) ;
    ) ;
    ) ;

    Apparently, this kind of thing doesn’t raise an eyebrow in the JS world.

    Now, I understand and respect the JS programming model. But this was seriously frustrating when I first encountered it because a simple script like the one I was trying to write just has an ordered list of tasks to complete. When it asks for bytes from a file, it really has nothing better to do than to wait for the answer.

    Thankfully, it turns out that Node’s fs module includes synchronous versions of the various file access functions. So it’s all good.

    Conclusion
    I’m sure I missed or underexplained some things. But if other brave souls are interested in dipping their toes in the waters of Emscripten, I hope these tips will come in handy.

    The post Things I Have Learned About Emscripten first appeared on Breaking Eggs And Making Omelettes.