SamuKata
Touhou-Project.com
Touhou-Project.com

patreon


Change that doesn't look like change

Hey guys, hope you’re doing well, I wanted to take the time to talk a little about the last round of changes on the site.  

As you may have noticed, there were a few changes to the user-facing portion of the site, best exemplified by the new settings menu and the toggable options there. Basically all the scripts that run on the site were modified or redone from scratch so there’s a lot that’s changed that may not be immediately obvious.

So what are these scripts, anyhow?

In case you’re not that webdev savvy, the (over)simplified explanation is that most of THP is static HTML content. Among other things it means that when pages are served to your browser it’s not expected that they’ll change their content on the fly. So any changes, like hiding a thread or expanding an image, is done on your side through scripts that are also loaded with the page.  

There’s a lot of caveats and details there that can be expanded upon but, for the purposes of clarity, all you have to know is that THP is dependent on javascript for most things that aren’t simply opening up pages.

Ok, I got all that. So why overhaul the scripts? Weren’t they working fine before?  

There’s a few reasons why I decided to make this a priority. The first reason is that a lot of the code was outright old. Not that old is bad by itself but a lot of it depended on libraries that were deprecated and no longer receiving audits or support. There are more modern (and often more efficient) ways of implementing some of the functionality that was needed for THP.  

Some of the practices by the developers of Kusaba X were less than ideal. Aside from depending on these older libraries, the site also made free use of a lot of inline scripts. This is to say, javascript that exists within the HTML instead of an external file. I’m not going to unequivocally state that this is awful but I’d rather continue moving to a stricter CSP (made easier by getting rid of inline content) as well as having scripts concentrated in a single file or two where it’s far easier to effect and keep track of changes.  

Finally, there is the factor that it’s easier to deal with code that you write yourself than something done by someone else. Given the very poor state of documentation and comments for Kusaba X code it is a big benefit to know what something is doing and why. I can add things or make changes without worrying that I might break something else.  

I’m politely nodding and pretending that I care about all this. Do go on about what you had to change and how.

Fine, I’ll keep this as brief as I can.  

I’ve talked about how most of the code on the site is intertwined and changing one thing often necessitates changing something else. Well, it was still like that this time around. It wasn’t just a matter of reverse-engineering scripts and their functionality based on what I could think of but I had to change a lot of the default HTML that is generated as well as some of the PHP functions and classes.  

There’s a lot in the code that assumes that the old scripts will be there. An example is how reflinks (when another post is displayed when you hover over a link) are generated. It makes an asynchronous call to a PHP file which then generates the HTML that is then ‘injected’ into the page. I had to change how it processed the data it needed to output the reflink correctly as it assumed an identifier from inline scripts.  

Even when I had the new code in place, there was still a lot that remained in the code base. I cleaned up a lot of the old stuff, removing superfluous code and in some case lightly rewriting bits and pieces of things to make it all work well together. Some of it wasn’t strictly necessary but simplifying the code base is a permanent secondary objective to any and all changes I’ve made to the site.  

Of course, there was a lot of testing and debugging all throughout the process. This made what should have been a strictly straightforward affair (just changing scripts and figuring out how to replicate functionality) into something more drawn out which is why it took me so long to push out changes. A lot of the code was written months earlier but, as I came closer to finishing my objectives, I revisited some of the earlier things I wrote in order to optimize and clean up.  

Ok, so we’re done, right? I’ll go back to looking at lewd images of shrine maidens if you don’t mind.

Wait a sec. There’s a few things to say about the final outcome.  

Pages are slightly lighter to load now. A few dozen KB, but it’s something. Should help mobile users as well as people with abysmal internet. All of the javascript now (at least the user-facing parts of the site) is now in external files, which is cacheable by browsers, further helping with loading for all users.  

The use of cookies has been minimized somewhat. Which is why your setting for style would have been reset—it’s now localstorage. I haven’t really done that for security reasons (though it doesn’t hurt either) but for efficiency as it skips having to send more cookies with the header when you open up a page. I’ll probably do some more in that area in the future.  

A lot of small, annoying bugs have also been fixed. Like how clicking on something might scroll you to the wrong place on the page and in some cases there being an extra line break that might change a reply’s formatting ever so slightly. Mostly stuff that only people who have used the site a lot would ever notice.  

I also wanted to quickly explain the rationale for the settings menu and the options there. Everything that wasn’t already covered by a button on the site, like hiding threads or inserting quote links into the reply box, I decided to make an option. There’s nothing on by default, allowing users to customize things according to their preferences. There are more options planned in the future but, for now, I think it’s a good starting point.  

Next time around I think I’ll talk about features that had to be scrapped as I was working on code for various reasons. But I’ll leave you with a small tease about what I’ll be looking at doing in the next week or two: it’s something regarding posts some people have asked about from time to time which helps in granting a little perspective.  

I don’t want to be more specific in case it proves not to be feasible. Nor do I want to put an ETA as some of the delays I’ve had of late have been due to things in my personal life, most recently less-than-stellar health. Still, I’ll be trying my best so that THP can keep getting even better!


More Creators